当使用.htaccess RewriteRule时,似乎POST值丢失. GET值确定.怎么修? [英] Seems like POST values are lost when .htaccess RewriteRule used. GET values are OK. How to fix?
问题描述
几天前,我有一个关于从地址栏中删除index.php的问题,因此页面的地址看起来更短,更好.这个问题的最短解决方案是( .htaccess文件中的RewriteRule ^ index.php/[L,R = 301] ).而且有效!
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屋!