Reputation: 75
I have a simple issue in redirecting a web site folder link. I have a main domain and lets say ABC.COM and I have a another subdomain XYZ.com. I have XYZ.com in the document root folder of ABC.com and the folder name is othersite. Everything works perfect, but when I type manually in browser like www.XYZ.com/hero , it takes m tot hat directory but url changes in browser and shows me www.XYZ.com/othersite/hero. I am not sure why it is doing so, but it works when I type www.XYZ.com/hero/ , i.e. with the / at the end.
Here what I have in my main htaccess in abc.com htaccess
RewriteEngine On
Options +FollowSymlinks
RewriteBase /
RewriteCond %{HTTP_HOST} ^xyz\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.xyz\.com$
RewriteCond %{REQUEST_URI} !^/othersite/
RewriteRule ^(.*)$ othersite/$1
Upvotes: 0
Views: 1233
Reputation: 143876
This is because mod_dir is turned on and will automatically redirect requests for directories that are missing the trailing slash to include the trailing slash. There's a information disclosure security risk when you don't do this:
Turning off the trailing slash redirect may result in an information disclosure. Consider a situation where
mod_autoindex
is active (Options +Indexes
) andDirectoryIndex
is set to a valid resource (say, index.html) and there's no other special handler defined for that URL. In this case a request with a trailing slash would show the index.html file. But a request without trailing slash would list the directory contents.
So you can turn off this auto-redirecting by including:
DirectorySlash Off
If you don't care about the issue of displaying a directory's contents instead of the index file. Alternatively, you can perform the redirect yourself before the internal rewrite to make sure there's a trailing slash but without exposing the internals:
RewriteCond %{DOCUMENT_ROOT}/othersite/%{REQUEST_URI} -d
RewriteCond %{REQUEST_URI} !/$
RewriteRule ^(.*)$ /$1/ [L,R=301]
then the rest of your rules.
Upvotes: 1