【发布时间】:2012-09-01 00:43:48
【问题描述】:
我有一个名为 www.mysite.com 的网站。当 url 是 www.mysite.com 时,我想调用 index1.php 文件(这是我的主域)。
如果 url 来自 test1.mysite.com、test2.mysite.com 等子域,那么我想调用 index2.php 文件。
在htaccess中怎么做?
【问题讨论】:
我有一个名为 www.mysite.com 的网站。当 url 是 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]
【讨论】:
http://mysite.com/ 或 http://www.mysite.com/ 并看到我的 index1.php 的内容文件。