How to call different index files for main domain and sub domains?

喜你入骨 提交于 2019-12-07 00:42:23

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]
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!