php - .htaccess RewriteRule 保留 GET URL 参数

标签 php .htaccess parameters url-rewriting

.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 时,我无法使用 $_GET['model' 在 PHP 中检索这些参数]$_GET['color'] 即使它们出现在显示的 URL 中。

为什么不传递变量?

最佳答案

您需要附加 [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

关于php - .htaccess RewriteRule 保留 GET URL 参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4071155/

相关文章:

php - 从数据库列 (php-mysql) 中选择的选项没有结果

javascript - 我有一个通过 ajax 调用返回选择选项的表单,但是当我保存后值不会显示

php - 使用php表单将图片上传到mysql

linux - URL 重写这个 .htaccess 的更好方法

regex - htaccess - 包含特定字符串部分的重定向字符串

apache - 基于接受语言的重定向

php - 将平面数组转换为要保存在数据库中的分隔字符串

c - 在c中将队列作为参数传递

objective-c - iOS:RestKit 加载对象并发送参数

bash - Linux shell 脚本: Is it possible to modify the variable sent as parameter to a function?