2009-10-08 65 views
2

如果我去http://www.example.com我希望它留在那裏,這是工作正常。
如果我去http://bar.example.com它重定向到http://www..com,這是不對的
它去http://www.example.com給出的RewriteCondRewriteCond反向引用不起作用

 
RewriteEngine On 

RewriteCond %{HTTP_HOST} !^$ 
RewriteCond %{HTTP_HOST} !^www.(example).com [NC] 
RewriteRule ^(.*)   http://www.%1.com/$1 [L,R] 

的Ubuntu 8.04
包反向引用:Apache2的-MPM-prefork的
建築:i386
版本:2.2.8-1

回答

3

否定的模式沒有比賽,因此你不能引用一組那個不存在的匹配。

但試試這個規則,而:

RewriteCond %{HTTP_HOST} !^$ 
RewriteCond %{HTTP_HOST} !^www\.example\.com$ [NC] 
RewriteRule ^(.*) http://www.example.com/$1 [L,R=301] 
+0

啊否定模式。現在一切都說得通了。謝謝! – er1234 2009-10-09 15:09:50

0

您的條件d OES不匹配bar.mysite.com:

RewriteCond %{HTTP_HOST} !^www.(mysite).com [NC] 

你需要去改變它,以獲得反向引用工作匹配:

RewriteCond %{HTTP_HOST} !^[^\.]+\.(mysite)\.com [NC]