我有一个以www.mysite.com为名的网站。当网址是www.mysite.com时,我想调用index1.php文件(这是我的主域)。
如果该URL来自像test1.mysite.com,test2.mysite.com这样的子域,那么我要调用index2.php文件。
如何在htaccess中完成?
如果它们都在同一文档根目录中,则将这样的内容放在文档根目录的htaccess文件中:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www\.)?mysite\.com$ [NC]
RewriteRule ^$ /index1.php [L]
RewriteCond %{HTTP_HOST} !^(www\.)?mysite\.com$ [NC]
RewriteRule ^$ /index2.php [L]
如果您具有需要重写的目录索引的链接,则可以根据具体情况进行操作,例如:
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]