I have a shared hosting plan that allows unlimited addon domains, but they can only point to the public root (/). I use .htaccess
to point different domains to their corresponding sub-directories. For example,
site1.com points to sub-directory /site1/
site2.com points to sub-directory /site2/
I don't want the user to see site1/
or site2/
. My .htaccess below almost works. If the user goes to a subdirectory like site2.com/test/
(notice the trailing slash /), it works great. But if the user leaves out the trailing slash it shows site2.com/site2/test/
in the browser.
So my question boils down to, how can I mask the sub-directory whether or not the user types the trailing slash?
My root .htaccess
looks like this (only with more domains, all in the same 3-lines per domain format)
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www.)?site1.com$ [NC]
RewriteCond %{REQUEST_URI} !site1/ [NC]
RewriteRule ^(.*)$ /site1/$1 [L]
RewriteCond %{HTTP_HOST} ^(www.)?site2.com$ [NC]
RewriteCond %{REQUEST_URI} !site2/ [NC]
RewriteRule ^(.*)$ /site2/$1 [L]
I've tried many things, from different online sources, but nothing works. One thing that almost worked (notice the trailing slash after $1
):
RewriteRule ^(.*)$ /site2/$1/ [L]
This works correctly when the filename is omitted - site2.com/test/
- but if you go to site2.com/test/index.php
it says "No input file specified."
The only file in root is .htaccess, everything else is in sub-directories.
Edit: Rewrote question, omitting irrelevant details.
www
subdomain and the bare domain? You should perhaps be forcing one or the other (as an external redirect) before your internal rewrites I would have thought. YourREQUEST_URI
line should probably match!^/sitec
rather than!sitec/
since the current pattern matches anywhere in the URI. Aresitea
,siteb
, etc. the real directories/domains?^
like you'd mentioned in your first comment, but it throws a 500 Internal Server Error.