使用 .htaccess RewriteRule 时,POST 值似乎丢失了.GET 值没问题.怎么修? [英] Seems like POST values are lost when .htaccess RewriteRule used. GET values are OK. How to fix?
问题描述
前几天有一个问题,关于从地址栏中删除index.php,这样页面的地址看起来更短更好.这个问题的最短解决方案是 (RewriteRule ^index.php/[L,R=301] 在 .htaccess 文件中).它有效!
Several days ago I had a question about removing index.php from the address bar, so the address of the page looks shorter and better. The shortest solution of this problem was (RewriteRule ^index.php / [L,R=301] in the .htaccess file). And it works!
由于我将该字符串放入 .htaccess 中,因此一些页面被重定向到主页.我花了很多时间去猜测,为什么.据我了解,答案是:使用 RewriteRule ^index.php/[L,R=301]
,$_POST 参数不会发送到下一页.$_GET 参数没问题.一旦我从 .htaccess 中删除 RewriteRule ^index.php/[L,R=301]
,一切都会像往常一样好.为什么会发生这种情况以及如何解决?
Since I put that string into the .htaccess, some pages are redirected to the main page. I spent a lot of time to guess, why. As I understand, the answer is: with RewriteRule ^index.php / [L,R=301]
, $_POST parameters are not sent to the next page. $_GET parameters are OK.
Once I remove RewriteRule ^index.php / [L,R=301]
from .htaccess, everything becomes fine as usual.
Why does it happen and how to fix that?
谢谢.
推荐答案
[R]
标志将导致重定向.用户代理以 GET
请求的形式发出重定向.如果您真的想将 URL 缩短到 /
根路径,则无能为力.
The [R]
flag will incur a redirect. And user-agents issue a redirect as GET
request. There is nothing that can be done if you really want to shorten URLs down to the /
root path.
然而,您可以专门阻止 POST 请求被重写/重定向:
You could however block POST requests specifically from being rewritten/redirected:
RewriteCond %{REQUEST_METHOD} !POST
RewriteRule ^index.php / [L,R=301]
这篇关于使用 .htaccess RewriteRule 时,POST 值似乎丢失了.GET 值没问题.怎么修?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!