开发者

.htaccess RewriteRule to preserve GET URL parameters

开发者 https://www.devze.com 2023-01-23 13:43 出处:网络
I\'m having issues keeping the parameters of the URL working after an .htaccess URL rewrite. My .htaccess rewrite is as follows:

I'm having issues keeping the parameters of the URL working after an .htaccess URL rewrite.

My .htaccess rewrite is as follows:

 RewriteEngine on
 RewriteRule ^([a-z]{2,2})/([a-zA-Z0-9_-]+)$ index.php?lang=$1&page=$2

Which means:

example.com/index.php?lang=en&page=product displays as example.com/en/product

For some reason, when I add a ?model=AB123&color=something at the end of my URLs I am not able to retrieve those parameters in PHP using $_GET['model'] and $_GET['color'] even though they are present in the displayed URL.

W开发者_如何学Chy aren't the variables passed along?


You need to append with the [QSA] (query string append) tag. Try

RewriteEngine on
RewriteRule ^([a-z]{2,2})/([a-zA-Z0-9_-]+)$ index.php?lang=$1&page=$2 [QSA]

See http://httpd.apache.org/docs/2.2/mod/mod_rewrite.html

0

精彩评论

暂无评论...
验证码 换一张
取 消