我的.htaccess文件规则不允许所有REQUEST_METHOD执行

问题描述 投票:0回答:1

我意识到我下面的.htaccess规则从URL中删除了PHP和HTML扩展名,从而拒绝了服务器上的所有帖子。

 #unless directory, removes the .php
RewriteBase /
RewriteRule ^(.+)\.php$ /$1 [R,L]
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*?)/?$ /$1.php [NC,END]

#unless directory, removes the .html
RewriteBase /
RewriteRule ^(.+)\.html$ /$1 [R,L]
RewriteCond %{REQUEST_FILENAME}.html -f
RewriteRule ^(.*?)/?$ /$1.html 

如果删除此规则,我的帖子将成功执行,但我不想使用文件扩展名。

php html .htaccess post submit
1个回答
0
投票

[我发现,如果我要求它仅在REQUEST_METHOD不发布时才重写条件,则它可以正常工作。

## To remove php extension unless it is directory ##
RewriteBase /
##The magic line. 
RewriteCond %{REQUEST_METHOD} !POST [NC]  
RewriteRule ^(.+)\.php$ /$1 [R,L]
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*?)/?$ /$1.php [NC,END]
© www.soinside.com 2019 - 2024. All rights reserved.