Luc*_*nte 5 php apache .htaccess mod-rewrite
我已添加此.htaccess以从URL中删除文件扩展名,因此改为"index.php",它将始终显示"index".但是在我做完之后,我<form method="post">停止了工作
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]
Run Code Online (Sandbox Code Playgroud)
这是一个例子:
/* 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">
Run Code Online (Sandbox Code Playgroud)
PS:如果我使用常规.htaccess规则,就像这样:
RewriteRule ^ index $ ./index.php [L,NC]
在所有情况下都不会隐藏.php
发生这种情况是因为您要在此处重定向:
## 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]
Run Code Online (Sandbox Code Playgroud)
重定向时,不一定总是包含请求BODY,您可以尝试为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]
Run Code Online (Sandbox Code Playgroud)
因为action您的表单指向/pwreset.php.当您尝试转到该页面时(即使是通过表单发布),htaccess会/pwreset在任何PHP代码运行之前将您重定向到.重定向将丢弃POST新请求中的任何数据.
您将不得不将所有这些表单操作更改为非PHP版本.作为短期修复,请尝试从重定向规则中排除POST请求
RewriteCond %{REQUEST_METHOD} !POST
| 归档时间: |
|
| 查看次数: |
4795 次 |
| 最近记录: |