RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www.)?domainname.com$
RewriteCond %{REQUEST_URI} !^/drupal/
RewriteRule ^(.*)$ /drupal/$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
The folder structure is as follows
public_html
/apps
/drupal
Currently when we give www.domainname.com it redirects to drupal folder and our website is displayed. We have some apps installed in apps folder and want to access it using the url www.domainname.com/apps and when we give this it goes to drupal framework and we get page not found.
What rule should we write to that when we give /apps in the url it should get into apps folder and all other times it should go to drupal folder.
Any help is appreciated. Thanks.
It looks like you're missing a line in the rewrite rules that you posted, but you just need to exclude the apps folder the same way you are excluding the drupal folder:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www.)?domainname.com$
RewriteCond %{REQUEST_URI} !^/drupal/
RewriteCond %{REQUEST_URI} !^/apps/
RewriteRule ^(.*)$ /drupal/$1 [L]
Related
I don't know much about the .htaccess file and need some assistance please. I have a few websites hosted one one CPanel account. I didn't want to have my "main" site stored directly in the public_html folder, so I moved it into a subfolder and then found this .htaccess configuration that allows me to load my main site from that subdirectory. So that is working.
# .htaccess main domain to subdirectory redirect
# Do not change this line.
RewriteEngine on
# Change example.com to be your main domain.
RewriteCond %{HTTP_HOST} ^(www.)?example.com$
# Change 'subdirectory' to be the directory you will use for your main domain.
RewriteCond %{REQUEST_URI} !^/example_directory/
# Don't change the following two lines.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# Change 'subdirectory' to be the directory you will use for your main domain.
RewriteRule ^(.*)$ /example.com/$1
# Change example.com to be your main domain again.
# Change 'subdirectory' to be the directory you will use for your main domain
# followed by / then the main file for your site, index.php, index.html, etc.
RewriteCond %{HTTP_HOST} ^(www.)?example.com$
RewriteRule ^(/)?$ example.com/index.html
So as I said, the above .htaccess will allow me to store my site files in a different folder rather than right at the root. But now I'm trying to force a redirect for this site over https as well. I found this site here:
Force Website to Use SSL
But, since I really don't understand the .htaccess file I'm having trouble integrating these two features together. Any help on this would be greatly appreciated. Thanks.
I'm pretty certain I figured this out myself. I just simply had to add this to the end of my .htaccess file:
RewriteCond %{HTTP_HOST} ^example\.com [NC]
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI}
and it works like a charm. Full .htaccess file looks like this, which changes the folder directory for the site to use and then forces it over https.
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www.)?example.com$
RewriteCond %{REQUEST_URI} !^/example_directory/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /example.com/$1
RewriteCond %{HTTP_HOST} ^(www.)?example.com$
RewriteRule ^(/)?$ example.com/index.html
RewriteCond %{HTTP_HOST} ^example\.com [NC]
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI}
I am an .htaccess newbie and am having problems in removing a folder name from my sites URL.
It is currently: www.mydomain.com/engine
I have an expression engine site in a subfolder (named engine) of my hosts html folder. In this folder I have an htaccess document in which I have followed the directions in the expressionengine user guide to remove the index.php? from the URL succesfully, with:
RewriteEngine On
# Removes index.php from ExpressionEngine URLs
RewriteCond $1 !\.(gif|jpe?g|png)$ [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
I would now like to remove the "engine" referring to the subfolder from the URL too.
I have made numerous attempts going on advice in previous questions but have had no success.
On viewing www.mydomain.com, with any of my attempts I recieve:
Forbidden. You don't have permission to access / on this server.
I thought this could be a permissions problem, but this containing html folder has the same permissions as the "engine" folder which allows access.
Can anybody help with the .htaccess code i require?
yeh, the above rules don't apply to homepage url because it's a directory (doesn't pass the third RewriteCond), use the code below:
RewriteEngine On
# Removes index.php from ExpressionEngine URLs
RewriteCond $1 !\.(gif|jpe?g|png)$ [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d [OR]
RewriteCond $1 ^$
RewriteRule ^(.*)$ /engine/index.php?/ [L]
I have Codeigniter installed and working for my main site.
But I am now trying to add an add-on domain to the same hosting account, so I can have two sites running on the same hosting. Add-on domains make a new folder in the main public_html folder to store the web files.
How can I get Codeigniter to ignore this directory? The site doesn't load properly when I try and view it.
I have an SSL on the main site too and redirection for www URLS. Here's my .htaccess file:
RewriteEngine on
Options +FollowSymLinks
RewriteBase /
RewriteCond %{HTTP_HOST} ^www\.mysite\.co.uk$ [NC]
RewriteRule ^(.*)$ http://mysite.co.uk/$1 [L,R=301]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php/$1
RewriteCond %{HTTPS} off
RewriteCond %{REQUEST_URI} (site|sections|here)
RewriteRule ^(.*)$ https://%{SERVER_NAME}%{REQUEST_URI} [R=301,L]
RewriteCond %{HTTPS} onsite|sections|here)
RewriteRule ^(.*)$ http://%{SERVER_NAME}%{REQUEST_URI} [R=301,L]
I have multiple domains on the same hosting two of which use CI. Don't change the main htaccess, only the one inside the folder containing the CI install. If your main site is directly in the public_html folder you may have to move it to it's own folder and redirect your URL to that folder, other than that this really shouldn't cause any issues.
I am trying to install CI under a directory which is also on a subdomain. So my base url would look like http://subdomain.domain.com/ci/
The following htaccess works fine on root of domain but not on directory, the browser says there is a redirect loop error.
Here is my code:
RewriteEngine on
RewriteCond %{HTTP_HOST} !^sub\.domain\.com/ci/$
RewriteRule ^(.*)$ http://sub.domain.com/ci/$1 [L,R=301]
RewriteCond $1 !^(index\.php|assets)
RewriteRule ^(.*)$ /index.php?/$1 [L]
I am not very skilled with mod rewrite, any help would be appreciated! Thank you!
Inside your /ci directory your htaccess should be as follows
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f # this means if the requested file name doesnt exist
RewriteCond %{REQUEST_FILENAME} !-d # this means if the requested directory doesnt exist
RewriteRule ^(.*)$ index.php [L]
Based on your above comments that should be sufficient
I'm hosting several domains on one account, and I currently have a RewriteRule set to redirect the root url (www.root.com) to a subdirectory (/public_html/root/).
However, I have few directories in the root (/public_html/xyz/) that I would like to access from the root url (www.root.com/xyz). Is this possible to write a redirect for this, or do I have to place these folder in the /public_html/root/ directory?
This is what I have for the .htaccess
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www.)?root.com$
RewriteCond %{REQUEST_URI} !^/root/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{HTTP_HOST} ^(www.)?root.com$
RewriteRule ^(/)?$ root/index.php [L]
Thanks in advance!
This sounds like job for a simple Alias.
Try this in your domain's VirtualHost:
Alias /xyz/ /public_html/xyz/