为什么在.htaccess中使用[QSA]时$_POST为空?

发布于 2024-10-12 10:32:37 字数 319 浏览 9 评论 0原文

我在 .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 技术交流群。

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

发布评论

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

评论(3

梦情居士 2024-10-19 10:32:37

以这种方式修改你的规则怎么样?它会改变什么吗?

RewriteRule ^(.*)\.htm$ index.php?url=$0.htm [QSA,L]

What about modifying your rule in this way. Does it change anything?

RewriteRule ^(.*)\.htm$ index.php?url=$0.htm [QSA,L]
似梦非梦 2024-10-19 10:32:37

我正是这个问题。它可以在一台服务器上运行,然后不能在下一台服务器上运行。至少可以说既烦人又耗时!

进行大量检查后,

foreach ($_REQUEST AS $key => $value) echo $value."<br>";

使用此 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:

foreach ($_REQUEST AS $key => $value) echo $value."<br>";

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!

皓月长歌 2024-10-19 10:32:37

默认情况下,.. 也许 apache 未启用 mod_rewrite,请尝试在控制台上键入此

sudo a2enmod rewrite

示例我的 .htaccess

<IfModule mod_rewrite.c>
  RewriteEngine On
  RewriteBase /
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>

<IfModule !mod_rewrite.c>
  ErrorDocument 404 /index.php
</IfModule>

by default,.. maybe apache not enable mod_rewrite, try type this on your console

sudo a2enmod rewrite

sample my .htaccess

<IfModule mod_rewrite.c>
  RewriteEngine On
  RewriteBase /
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>

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