为什么在.htaccess中使用[QSA]时$_POST为空?
我在 .htaccess 中有以下内容:
RewriteCond %{REQUEST_URI} !app/index\.php$
RewriteRule ^(.*\.htm)$ index.php?url=$0 [QSA,L]
一切都很好,但结果 URL 有空 $_POST。
我 100% 确定这是 mod_rewrite 错误,而不是 HTML 或 PHP,因为当我将 [QSA,L] 更改为 [L] 时,它效果很好。但我确实需要 QSA。
大约 30% 的主机会出现这种情况,因此这可能是某个 Apache 配置选项。
I've got the following in .htaccess:
RewriteCond %{REQUEST_URI} !app/index\.php$
RewriteRule ^(.*\.htm)$ index.php?url=$0 [QSA,L]
Everyting works great but result URLs have empty $_POST.
I'm 100% sure that it's mod_rewrite bug, not HTML or PHP because when I change [QSA,L] to [L] it works great. But I really need QSA.
It happens at about 30% hostings so this may be some Apache config option.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
以这种方式修改你的规则怎么样?它会改变什么吗?
What about modifying your rule in this way. Does it change anything?
我正是这个问题。它可以在一台服务器上运行,然后不能在下一台服务器上运行。至少可以说既烦人又耗时!
进行大量检查后,
使用此 php:在 index.php 顶部 检查从 htaccess 文件发送的值(以及我不会讨论的许多其他检查!)我最终发现您需要指定“RewriteBase “
将
RewriteBase /
添加到 htaccess 文件的顶部使其可以在我尝试过的所有服务器上运行。(另外,请记住设置为:
RewriteBase /folder-where-file-is/
其中“folder-where-file-is”是index.php文件的位置(如果在子文件夹中)
希望它能帮助你 - 知道这肯定会在很多个小时前帮助我!
I had exactly this issue. It works on one server then not the next. Annoying and time consuming to say the least!
After a lot of checking using this php:
at the top of the index.php to check what values were being sent from the htaccess file, (and many other checks I will not go into!) I eventually found you need to specify "RewriteBase"
Adding
RewriteBase /
to the top of the htaccess file made it work on the all the servers I tried.(also, remember to set to:
RewriteBase /folder-where-file-is/
where "folder-where-file-is" is the location of the index.php file if in a sub-folder)
Hope it helps you - knowing this would certainly have helped me many many hours ago!
默认情况下,.. 也许 apache 未启用 mod_rewrite,请尝试在控制台上键入此
sudo a2enmod rewrite
示例我的 .htaccess
by default,.. maybe apache not enable mod_rewrite, try type this on your console
sudo a2enmod rewrite
sample my .htaccess