Mod_rewrite and $ _GET variables

If I mod_rewriting URL from:

http://www.mysite.com/blog/this-is-my-title/1/

to

http://www.mysite.com/blog.php?title=this-is-my-title&id=1

... is it then possible to arbitrarily attach the get value to the URL later or disable mod_rewrite?

MY RULE MODE:

RewriteRule ^blog/([A-Za-z]+)/(0-9]+)/? blog?title=$1&id=$2 [L] 

Example:

Can I go http://www.mysite.com/blog/this-is-my-title/1/?first=Johnnie&last=Wiggles

which would mean

http://www.mysite.com/blog.php?title=this-is-my-title&id=1&first=Johnnie&last=Wiggles

I would think that this should work, but for some reason this is not for me at the moment.

+4
source share
2 answers

You can add QSA to the RewriteRule flags:

 RewriteRule page_([0-9]+)\.html page.php?id=$1 [QSA] 

Redirects page_1.html?a=2 to page.php?id=1&a=2

However, be careful, because the request page_1.html?id=2 will be redirected to page.php?id=1&id=2 and (in PHP), $_GET['id'] will be 2.

+9
source

You can add it with the QSA flag (add query string).

 RewriteEngine on RewriteRule {from-url} {to-url} [L,NC,QSA] 
+3
source

All Articles