.htaccess RewriteRule保留GET URL参数

时间:2022-06-20 08:48:28

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

在重写htaccess url之后,url的参数仍然正常工作,我遇到了一些问题。

My htaccess rewrite is as follows:

我的htaccess重写如下:

 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

domain.com/index.php?domain.com/en/product lang = en&page =产品展示

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.

由于某些原因,当我在URL末尾添加?model=AB123&color=时,我无法使用$_GET['model']和$_GET['color']在php中检索这些参数,即使它们存在于显示的URL中。

Why aren't the variables passed along?

为什么不传递变量呢?

1 个解决方案

#1


63  

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

您需要附加[QSA](查询字符串附加)标记。试一试

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

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

#1


63  

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

您需要附加[QSA](查询字符串附加)标记。试一试

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

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