Sign up ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

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,one.html I want it only on,one.html or,one.html

What is wrong?

share|improve this question

1 Answer 1

up vote 2 down vote accepted

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,,one.html will not redirect you - but,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]
share|improve this answer
Yes, that's it! :) Thanks a lot. – Kamilos Jun 14 '12 at 5:41
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 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)". – Shane Madden Jun 14 '12 at 16:47

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.