Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am trying to write a redirect rule that says "If the HTTP_REFERER contains a certain QUERY_STRING, do this..."

In other words, I have this scenario:


... and I would like to say, "If the HTTP_REFERER contains the QUERY_STRING 'foo=bar', do this..." Make sense? Lol

Maybe it's not even possible? I'm relatively new to mod_rewrite.

share|improve this question
If you work out your own solution, just post it as an answer. Don't delete a good resource. – random Oct 3 '09 at 15:45
up vote 1 down vote accepted

As it turns out, the QUERY_STRING is already a part of the HTTP_REFERER.

So the solution is simple:

RewriteCond %{HTTP_REFERER} !foo=bar
share|improve this answer

Try this RewriteCond:

RewriteCond %{HTTP_REFERER} ^[^?]+\?([^&]*&)*foo=bar(&.*)?$
share|improve this answer

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.