Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

.htaccess rewrite pretty urls that can still use get variables

I'm trying to write an .htaccess line that will rewrite to a php script but still allow any extra get variables to be added on the end. Is this possible?

Currently I'm trying to use this:

RewriteRule ^item/([^/]*)([^/]*)$ /item.php?id=$1&$2 [L]

The aim is to be able to do things like blah.com/item/foo, but also blah.com/item/foo?bar=whatever.

Currently it seems to correctly pass the first part, id, but not the rest.

like image 518
MHG Avatar asked Mar 01 '13 19:03

MHG


2 Answers

RewriteRule ^item/([^/]*)([^/]*)$ /item.php?id=$1&$2 [L,QSA]

You can read more about QSA (query string append) here: https://httpd.apache.org/docs/2.0/mod/mod_rewrite.html

like image 150
str Avatar answered Oct 03 '22 14:10

str


You need to finish with [L,QSA]

like image 27
Eric Avatar answered Oct 03 '22 15:10

Eric