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

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

Im trying to add a rewrite rule to my htcaccess file and the part Im having trouble wth is the query string. I want to add the query string parameter pid to the rewrite rule. Both lines of code don't work how do set up query string for you're rewrite rules.

RewriteRule browse/(.*)/?pid=(/d+) show_products.php?department=$1&pid=$2
RewriteRule browse/(.*)/?pid=([0-9]+) show_products.php?department=$1&pid=$2

should look like


i've got it to do this but it has no question mark does anyone know how to get it to have the question mark

RewriteCond %{QUERY_STRING} ^$
RewriteRule browse/(.*)/pid=([0-9]+)$ show_products.php?department=$1&pid=$2
share|improve this question
Your edit isn't very clear. If you're trying to say that something didn't work, provide an example of what didn't. (hint: question marks in a regex need to be escaped) – Andrew B Apr 6 '13 at 4:24
up vote 1 down vote accepted

RewriteRules do not directly match query strings. You need to use something like

RewriteCond %{QUERY_STRING} ^pid=([0-9]+)
RewriteRule browse/(.*)/ show_products.php?department=$1&pid=%1

Not tested but that should be close.

share|improve this answer
I tried you're example and it didn't work i've updated my code and I got something close but its not quite exact I want the question mark in there for querying – ONYX Apr 6 '13 at 3:26
I got it working thanks for you're help – ONYX Apr 6 '13 at 4:04
@KDM This really isn't how the Q&A system is designed to be used; anyone who comes along and sees this question isn't going to understand what the solution was. Please elaborate on what your final solution was. – Andrew B Apr 6 '13 at 4:28

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.