1

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?

1 Answer 1

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]
2
  • 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, 2012 at 8: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)". Jun 14, 2012 at 16:47

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .