PHP方法="邮电QUOT;停止后,我说这的.htaccess ......为什么要工作?我说、邮电、方法、工作

2023-09-02 00:23:28 作者:得不到的就毁灭

我把这个添加的.htaccess删除的文件扩展名的URL,这样反而的index.php,它会显示指数而已,所有的时间。但经过我做到了,我的<形式方法=邮报> 停止工作

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.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]

当你重定向,请求主体并不总是得到包括不,你可以尝试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]