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



我意识到,下面的.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 

如果我删除了这些规则,我的帖子就会成功执行,但我不想使用文件扩展名。

我发现,如果我要求它重写条件,只有当REQUEST_METHOD没有POST时,它才能完美工作。

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

最新更新