How to call different index files for main domain and sub domains?

a 夏天 提交于 2019-12-08 05:50:50

问题


I have a site in the name of www.mysite.com. when the url is www.mysite.com, I want to call index1.php file (this is my main domain).

If the url is from sub domains like test1.mysite.com, test2.mysite.com then I want to call index2.php file.

How to do it in htaccess?


回答1:


If they are both in the same document root, put something like this in your htaccess file in the document root:

RewriteEngine On

RewriteCond %{HTTP_HOST} ^(www\.)?mysite\.com$ [NC]
RewriteRule ^$ /index1.php [L]

RewriteCond %{HTTP_HOST} !^(www\.)?mysite\.com$ [NC]
RewriteRule ^$ /index2.php [L]

If you have links to directory indexes that need to be rewritten, you can do those on a case-by-case basis, for example:

RewriteCond %{HTTP_HOST} ^(www\.)?mysite\.com$ [NC]
RewriteRule ^(.*)/index\.(php|html|htm)$ /$1/index1.php [L]

RewriteCond %{HTTP_HOST} !^(www\.)?mysite\.com$ [NC]
RewriteRule ^(.*)/index\.(php|html|htm)$ /$1/index2.php [L]


来源:https://stackoverflow.com/questions/12312906/how-to-call-different-index-files-for-main-domain-and-sub-domains

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