简体   繁体   English

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

[英]My .htaccess file rules not allowing all REQUEST_METHOD to execute

I realized that my .htaccess rules below to remove PHP and HTML extensions from the URL are denying all posts on the server.我意识到我下面从 URL 中删除 PHP 和 HTML 扩展的 .htaccess 规则拒绝了服务器上的所有帖子。

 #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 

If I remove this rules, my posts are executed successfully but I don't want to use the file extensions.如果我删除此规则,我的帖子将成功执行,但我不想使用文件扩展名。

I found that if I ask it to rewrite the condition only when the REQUEST_METHOD not POST it works perfectly.我发现如果我要求它仅在 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]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM