简体   繁体   中英

htaccess url rewriting, query parameters are not available in script

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.

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']

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM