Question

I am using following rule to rewrite a url in directory style,

RewriteRule ^post/([0-9]+)$ post.php?pid=$1

by using this i am directing localhost/post.php?pid=3 to localhost/post/3

but now I want to pass more parameters in default way like ?key=value.

for example localhost/post/3?comment_id=23 but this key value pair is not available in script. When I do echo $_GET['comment_id'] it's not echo'ing anything.

How do I get it done.

Was it helpful?

Solution

You need to use QSA (query string append) flag. Change your rule to:

RewriteRule ^post/([0-9]+)$ post.php?pid=$1 [L,QSA]

QSA flag will append pid query parameter while preserving original query string in the URI thus you can do:

$_GET['comment_id']

and also:

$_GET['pid']
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top