PHP方法=“发布"添加此 .htaccess 后停止工作......为什么? [英] PHP method="post" stopped working after I added this .htaccess... Why?

查看:22
本文介绍了PHP方法=“发布"添加此 .htaccess 后停止工作......为什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已添加此 .htaccess 以从 URL 中删除文件扩展名,因此,它始终只显示index.php",而不是index.php".但是在我这样做之后,我的 <form method="post"> 停止工作

I've added this .htaccess to remove file extension from the URL, so instead "index.php", it would show "index" only, all the times. But after I did it, my <form method="post"> stopped working

Options +FollowSymLinks -MultiViews
Options +Indexes
AcceptPathInfo Off
RewriteEngine on
RewriteBase   /

#Force from http to https
RewriteCond %{SERVER_PORT} 80 
RewriteCond %{HTTP_HOST} !^mysite.com$
RewriteRule ^(.*)$ https://mysite.com/$1 [R=301]

#take off index.html
 RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{REQUEST_URI} ^(.*/)index\.html$ [NC]
RewriteRule . http://www.%{HTTP_HOST}%1 [R=301,NE,L]

## hide .php extension
# To externally redirect /dir/foo.php to /dir/foo
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.php [NC]
RewriteRule ^ %1 [R,L,NC]

## To internally redirect /dir/foo to /dir/foo.php
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^ %{REQUEST_URI}.php [L]    

## hide .html extension
# To externally redirect /dir/foo.html to /dir/foo
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.html [NC]
RewriteRule ^ %1 [R,L,NC]

## To internally redirect /dir/foo to /dir/foo.html
RewriteCond %{REQUEST_FILENAME}.html -f
RewriteRule ^ %{REQUEST_URI}.html [L]  

这是一个例子:

/* Worked before .htaccess, but not anymore */

    <form method="post" action="pwreset.php"  class="form-stacked">

/* Removing .php from action works. But there are hundreds of files and this method is not very trustworthy */

    <form method="post" action="pwreset"  class="form-stacked">

PS:如果我使用常规的 .htaccess 规则,就像这样:

PS: If I use regular .htaccess rules, like this one:

重写规则 ^index$ ./index.php [L,NC]

RewriteRule ^index$ ./index.php [L,NC]

它不会在所有情况下隐藏 .php

It won't hide .php in all cases

推荐答案

发生这种情况是因为您重定向到此处:

This is happening because you are redirecting here:

## hide .php extension
# To externally redirect /dir/foo.php to /dir/foo
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.php [NC]
RewriteRule ^ %1 [R,L,NC]

重定向时,请求 BODY 并不总是包含在内,您可以尝试为 POST 添加异常:

When you redirect, the request BODY doesn't always get included, you can try adding an exception for POST:

## hide .php extension
# To externally redirect /dir/foo.php to /dir/foo
RewriteCond %{REQUEST_METHOD} !POST [NC]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.php [NC]
RewriteRule ^ %1 [R,L,NC]

这篇关于PHP方法=“发布"添加此 .htaccess 后停止工作......为什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆