如何为主域和子域调用不同的索引文件?

问题描述 投票:1回答:1

我有一个以www.mysite.com为名的网站。当网址是www.mysite.com时,我想调用index1.php文件(这是我的主域)。

如果该URL来自像test1.mysite.com,test2.mysite.com这样的子域,那么我要调用index2.php文件。

如何在htaccess中完成?

.htaccess url subdomain
1个回答
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]
© www.soinside.com 2019 - 2024. All rights reserved.