php - mod_rewrite 之后查询字符串被忽略

标签 php apache mod-rewrite query-string

我在 .htaccess 文件中使用以下重写规则将所有请求发送到位于根目录的 index.php 文件:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.*) index.php?q=$1 [L]

正如我所料,像 example.com/users 这样的 url 将导致 php 接收 ["q"]=> string(5) "users" 作为 $ _GET 变量。

另一方面,像 example.com/users?fu=bar 这样的 URL 不会导致 php 接收

["q"]=> string(5) "users", 
["fu"]=> string(3) "bar"

这里发生了什么,我如何修改我的规则以实现这种方式?

最佳答案

您需要添加原始查询字符串:

RewriteRule (.*) index.php?q=$1 [L,QSA]
                                   ^^^ here

关于php - mod_rewrite 之后查询字符串被忽略,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16345260/

相关文章:

.htaccess - 如何使 .htaccess 在当前目录而不是子目录上工作?

php - MySQL DELETE 查询未执行

php - nodejs & socket.io vs php - 验证并集成到 php 应用程序

php - 组织一个PHP项目

java - 不能在 Apache nutch 2.3 中运行 ant 运行时

regex - .htaccess 重写问题

apache - 使用 .htaccess 将 example.(us|es) 重定向到子域 (us|es).example.com

php - 字符串转换为数组

linux - Dockerfile 中的 sed 命令不会被执行或被覆盖

.htaccess 重写语言子域