问题
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