Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.2k views
in Technique[技术] by (71.8m points)

php - .htaccess RewriteRule to preserve GET URL parameters

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:

domain.com/index.php?lang=en&page=product displays as domain.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.

Why aren't the variables passed along?

question from:https://stackoverflow.com/questions/4071155/htaccess-rewriterule-to-preserve-get-url-parameters

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...