0

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 
1
  • 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) Commented Apr 6, 2013 at 4:24

1 Answer 1

1

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.

2
  • 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 Commented Apr 6, 2013 at 3:26
  • @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. Commented Apr 6, 2013 at 4:28

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.