.htaccess rewrite pretty urls that can still use g

2019-06-19 17:20发布

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.

2条回答
虎瘦雄心在
2楼-- · 2019-06-19 17:40
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

查看更多
该账号已被封号
3楼-- · 2019-06-19 17:58

You need to finish with [L,QSA]

查看更多
登录 后发表回答