如何调用主域和子domins不同的索引文件?(How to call different index

2019-09-22 05:22发布

我在www.mysite.com名的网站。 当网址是www.mysite.com,我想打电话给index1.php文件(这是我的主域名)。

如果URL是从像test1.mysite.com,test2.mysite.com子域的话,我想打电话给index2.php文件。

怎么办呢htaccess的? 任何帮助是极大的赞赏..

提前致谢。!

Answer 1:

如果他们都在同一个文档根目录,把像这样在文档根目录的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]


文章来源: How to call different index files for main domain and sub domins?