RewriteCond backreference not working

If I go to http://www.example.com

, I want it to stay there and it works great.
If I go to http://bar.example.com

it redirects to http://www..com

, which is not correct. I want to jump to http://www.example.com

given backlink inRewriteCond

RewriteEngine On

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

Ubuntu 8.04
Package: apache2-mpm-prefork
Architecture: i386
Version: 2.2.8-1

+2


source to share


2 answers


Negative patterns do not match, and therefore you cannot refer to the group of this non-existent match.

But try this rule:



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

      

+3


source


Your state does not match bar.mysite.com:

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

      



You need to change it to match in order to make the backreference work:

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

      

0


source







All Articles