Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mod_rewrite and $_GET variables

If I am mod_rewriting a 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 possible then to arbitrarily attach a get value on to the URL later, or does the mod_rewrite throw it off?

MY REWRITE RULE:

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 essentially mean

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

I would think that should work, but for some reason it's not for me at the moment.

like image 214
johnnietheblack Avatar asked Dec 18 '22 05:12

johnnietheblack


1 Answers

You can add QSA to the RewriteRule flags:

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

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

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

like image 96
Julien Avatar answered Dec 29 '22 04:12

Julien