Possible Duplicate:
Query Strings & Mod ReWrite
I have written a .htaccess file which correctly translates the following line into
http://localhost/questions/32/new-question-from-peter
into
http://localhost/questions.php?question_id=32.
The code I use is
RewriteRule ^questions/([0-9]+)/[^/]*(?:\?(.+)=(.*))?$ public/questions.php?question_id=$1&$2=$3 [NC,L]
However when the url is the following,
http://localhost/questions/32/new-question-from-peter?page= <int>
it will not process the page information correctly even though when my url is
http://localhost/questions.php?question_id=32&page=2
it works perfectly.
Can someone help me with this please, where in my code have I gone wrong
You should use the QSA
(Query String Append) flag, like this:
RewriteRule ^questions/([0-9]+)/[^/]*/?$ public/questions.php?question_id=$1 [NC,L,QSA]
The query string (&page=2
) is handled automatically in this case, so you don't need to deal with it in your regular expression, and is appended to the end of the rewritten URL.
A good, general way to debug mod_rewrite is to set up a logfile and check what goes on during rewriting:
<IfModule mod_rewrite.c>
RewriteLog "/var/log/rewrite.log"
RewriteLogLevel 3
</IfModule>