2

I have a set of requirements for mod_rewrite that is breaking my head. Any hints / pointers would be appreciated:

domains:

www.domain-europe.com
www.domain.com
  1. requests for www.domain-europe.com should be redirected to www.domain.com/europe
  2. requests for www.domain-europe.com/someurl should be redirected to www.domain.com/someurl
  3. any other request coming to the server that is not www.domain-europe.com or www.domain.com should be set to www.domain.com

I can make any 1 and 3 or 2 and 3 of these work, but not all three at the same time.

Here is one of the many iterations I have tried:

RewriteEngine on

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

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

RewriteCond %{HTTP_HOST}   !^www\.domain\.com [NC]
RewriteCond %{HTTP_HOST}   !^$
RewriteRule ^/(.*)         http://www.domain.com/$1 [L,R]
Nidal
  • 187
mdekkers
  • 224

1 Answers1

1

Your rewrite conditions are only matching on the HTTP host, not on the request uri - and your rewrite rule (.*) matches everything...

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

will match anytime the host is www.domain-europe.com, regardless of whether / is requested, or /foo/bar/virus.exe is requested.

Instead, perhaps try something more like:

RewriteCond %{HTTP_HOST} ^(www\.)?domain-europe\.com$ [NC]
RewriteRule ^/$ http://www.domain.com/europe [R=301,L]
RewriteRule ^/(.+)$ http://www.domain.com$1 [R=301,L]

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

You might still have to tweak it some. I'm a bit rusty on the exact semantics - but this should at least point you in the right direction.

HTH