.htaccess RewriteRule 保留 GET URL 参数 [英] .htaccess RewriteRule to preserve GET URL parameters

查看:37
本文介绍了.htaccess RewriteRule 保留 GET URL 参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 htaccess url 重写后,我在保持 url 参数正常工作时遇到问题.

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

我的htaccess重写如下:

My htaccess rewrite is as follows:

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

这意味着:

domain.com/index.php?lang=en&page=product 显示为 domain.com/en/product

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

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.

为什么不传递变量?

推荐答案

您需要附加 [QSA](查询字符串附加)标签.试试

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]

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

这篇关于.htaccess RewriteRule 保留 GET URL 参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆