1

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.

1
  • You could try removing the $ from ^post/([0-9+)$ this means ends with, I'm not sure if that will actually work or not but it's a good place to start Commented Jun 10, 2013 at 11:01

1 Answer 1

1

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']
Sign up to request clarification or add additional context in comments.

2 Comments

that worked, thanks...can you give me any link if you know, where I can learn more about this and other flags.
@vikasdevde: Use this link: httpd.apache.org/docs/2.2/rewrite/flags.html Also if this answer helped you solve your problem, please consider marking it as "accepted", so users facing a similar problem in the future will be able to see it easily.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.