问题
Once more I turn to SO when I am at my wits end. A client of mine is running three separate websites on a single hosting plan. What I need to do is shift the main domain contents to a sub-folder and link the main domain to it so that
maindomain.com/
actually gets linked to
/maindomain/
This i got working with
RewriteCond %{HTTP_HOST} ^(www.)?maindomain.com/$
RewriteCond %{REQUEST_URI} !^/maindomain/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /maindomain/$1
RewriteCond %{HTTP_HOST} ^(www.)?maindomain.com$
RewriteRule ^(/)?$ maindomain/index.html [L]
The Second part is the problem. I now need prevent addon domains domainA and domainB from being accessed from the main domain.To make matters more complicated, domainA is running cakePHP and domainB is running a custom framework which is totally dependent on its .htaccess
the domains lie in sub-folders of webroot as
/domainA/
and
/domainB/
I tried the following but it didn't prevent access to the add-on domains.
RewriteCond %{HTTP_HOST} ^(www.)?maindomain.com$ [NC]
RewriteCond %{REQUEST_URI} ^/domainA/(.*)$ [OR]
RewriteCond %{REQUEST_URI} ^/domainB/(.*)$ [OR]
RewriteRule ^(.*)$ - [L,R=404]
I could really use some insight on what to do.
回答1:
Place this rule as very first rule in both /domainA/.htaccess
and /domainB/.htaccess
files:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www\.)?maindomain\.com$ [NC]
RewriteRule ^ - [L,R=404]
来源:https://stackoverflow.com/questions/25854352/how-do-i-shift-main-domain-root-to-subfolder-and-prevent-access-to-addon-domains