0

I'm trying to create a rewrite condition in .htaccess file to check if url contains a parameter p that is set and parameter p=about or p=contact. In case, if ?p=about or ?p=contact, the RewriteRule that is below should NOT be berformed. Could anybody help me with RewriteCond?

RewriteCond %{REQUEST_URI} (?p=about_us|?p=contact)

does NOT work.

Haradzieniec
  • 9,086
  • 31
  • 117
  • 212

1 Answers1

6

The RewriteCond below will match if the query string does not have a p param with a value of about us or contact i.e the following rule will not execute if it has a p= about us or contact

RewriteCond %{QUERY_STRING} !(^|&)p=(about_us|contact)(&|$) [NC]
Ulrich Palha
  • 9,411
  • 3
  • 25
  • 31
  • Not sure who downvoted... its a nice answer. I will upvote it now. However you may know OP wanted to skip the rules if above condition is met so you pls put negation `!` like this: `RewriteCond %{QUERY_STRING} !(^|&)p=(about_us|contact)(&|$) [NC]` – anubhava Jan 19 '12 at 20:09
  • @anubhava Thanks! I missed the negation but its now in – Ulrich Palha Jan 19 '12 at 20:21
  • I'm also not sure who downvoted. I've tested it, and it works. That's a solution for my question. Thank you very much! – Haradzieniec Jan 20 '12 at 14:23