Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/apache/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/.htaccess/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Apache 特定于域的重写规则也与其他域匹配_Apache_.htaccess_Mod Rewrite_Url Rewriting - Fatal编程技术网

Apache 特定于域的重写规则也与其他域匹配

Apache 特定于域的重写规则也与其他域匹配,apache,.htaccess,mod-rewrite,url-rewriting,Apache,.htaccess,Mod Rewrite,Url Rewriting,我在一台服务器上托管了几个域,我有一个.htaccess文件,类似于以下内容: # FIRST.COM RewriteCond %{HTTP_HOST} !^www\.first\.com$ [NC] RewriteCond %{HTTP_HOST} ^(www\.)?([^.]+)\.first\.com$ [NC] RewriteCond %{REQUEST_URI} !index\.php [NC] RewriteRule ^(.*)$ /index.php?q=%2 [L,QSA,N

我在一台服务器上托管了几个域,我有一个
.htaccess
文件,类似于以下内容:

# FIRST.COM
RewriteCond %{HTTP_HOST} !^www\.first\.com$ [NC]
RewriteCond %{HTTP_HOST} ^(www\.)?([^.]+)\.first\.com$ [NC]
RewriteCond %{REQUEST_URI} !index\.php  [NC]
RewriteRule ^(.*)$ /index.php?q=%2  [L,QSA,NC]

# there are some more rules for first.com here ...

# SECOND.COM
RewriteCond %{HTTP_HOST} !^www\.second\.com$ [NC]
RewriteCond %{HTTP_HOST} ^(www\.)?([^.]+)\.second\.com$ [NC]
RewriteCond %{REQUEST_URI} !index\.php  [NC]
RewriteRule ^(.*)$ /index.php?q=%2  [L,QSA,NC]

# there are some more rules for second.com here ...

# THIRD.COM
RewriteCond %{HTTP_HOST} !^www\.third\.com$ [NC]
RewriteCond %{HTTP_HOST} ^(www\.)?([^.]+)\.third\.com$ [NC]
RewriteCond %{REQUEST_URI} !index\.php  [NC]
RewriteRule ^(.*)$ /index.php?q=%2  [L,QSA,NC]
基本上所有域都指向一个脚本,但是它们的重写规则略有不同

我现在刚刚添加了third.com规则,我意识到所有的网站(甚至那些在.htaccess文件中没有任何重写规则的网站)现在都将转到third.com

第三个.com规则就在.htaccess文件的底部,如果我删除它们,上面所有的规则都会很好地工作。第一个和第二个域有很多规则,它们都可以正常工作,它们可以做任何预期的事情,但是当我添加这四行时,没有任何规则匹配,所有请求都会匹配第三个.com规则

有人知道我应该如何调试这个吗


提前谢谢。

你怎么知道
http://fourth.com/abc
将进入
third.com
?@anubhava我对每个项目的设置略有不同,third.com将为您提供淡黄色,其他为淡红色…仅用于测试在所有
RewriteRule
行中添加
R
标志,如
[L,QSA,NC,R]
并查看浏览器中的重定向URL。@anubhava我做到了。它只是重定向到第三个域……虚拟主机会有问题吗?现在您可以看到
http://third.com/index.php?q=foo
对于每个URL,即使您输入:
http://foo.firstd.com/