如何为主域和子域调用不同的索引文件? [英] How to call different index files for main domain and sub domains?

查看:94
本文介绍了如何为主域和子域调用不同的索引文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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).

如果该网址来自test1.mysite.com,test2.mysite.com等子域,那么我想调用index2.php文件。

If the url is from sub domains like test1.mysite.com, test2.mysite.com then I want to call index2.php file.

如何在htaccess中进行操作?

How to do it in htaccess?

推荐答案

如果它们都在同一文档根目录中,将这样的内容放在文件根目录的htaccess文件中:

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]

这篇关于如何为主域和子域调用不同的索引文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆