Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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

http://mysite.com/browse/department?pid=1

or

http://mysite.com/browse/department/?pid=1

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 

http://mysite.com/browse/department/pid=1
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
add comment

1 Answer 1

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 –  KDM Apr 6 '13 at 3:26
    
I got it working thanks for you're help –  KDM 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
add comment

Your Answer

 
discard

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.