0

I have in htaccess some like this:

RewriteCond %{HTTP_HOST} !^foo
RewriteCond %{HTTP_HOST} !^bar
RewriteCond %{HTTP_HOST} !^some
RewriteRule ^register,(.*)$ /register.html [R=301,L]
RewriteRule ^offer,(.*)$ /offer.html [R=301,L]

It redirect me if I write http://foo.domain.com/register,one.html I want it only on http://domain.com/register,one.html or http://www.domain.com/register,one.html

What is wrong?

Kamilos
  • 225
  • 1
  • 3
  • 9

1 Answers1

4

In the example that you've given, you will most certainly not be redirected.

However, it looks like you're expecting the RewriteCond directives to apply to both of the RewriteRule directives - they do not. They only apply to the RewriteRule that immediately follows them.

So, in your example, http://foo.domain.com/register,one.html will not redirect you - but http://foo.domain.com/offer,one.html will.

What you probably need is something more along these lines:

RewriteCond %{HTTP_HOST} !^(foo|bar|some)
RewriteRule ^register,(.*)$ /register.html [R=301,L]
RewriteCond %{HTTP_HOST} !^(foo|bar|some)
RewriteRule ^offer,(.*)$ /offer.html [R=301,L]
Shane Madden
  • 112,982
  • 12
  • 174
  • 248
  • 1
    Consecutive `RewriteCond` directives have an implicit *AND* between them and since yours are mutually exclusive, the `RewriteRule` would never be reached. Shane's example deals with that problem too. You can also place `[OR]` after a `RewriteCond`. – Ladadadada Jun 14 '12 at 08:00
  • @Ladadadada Actually, it's functionally equivalent, I was just going for extra efficiency and ease of reading. He's got `!` preceding those condition match strings, so they're all negative matches - "(not A) and (not B) and (not C)", while mine is "not (A or B or C)". – Shane Madden Jun 14 '12 at 16:47