How do I shift main domain root to subfolder and prevent access to addon domains from main domain at the same time?

我只是一个虾纸丫 提交于 2019-12-11 13:55:49

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!