.htaccess RewriteRule 保留 GET URL 参数

发布于 2024-09-30 11:42:43 字数 527 浏览 0 评论 0原文

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

我的 .htaccess 重写如下:

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

这意味着:

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

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

为什么变量不被传递?

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.

Why aren't the variables passed along?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

不美如何 2024-10-07 11:42:43

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

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

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文