当使用.htaccess RewriteRule时,似乎POST值丢失. GET值确定.怎么修?

编程入门 行业动态 更新时间:2024-10-15 08:19:25
本文介绍了当使用.htaccess RewriteRule时,似乎POST值丢失. GET值确定.怎么修?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

几天前,我有一个关于从地址栏中删除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值确定.怎么修?

本文发布于:2023-10-11 14:14:26,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1481937.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:htaccess   RewriteRule   POST

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!