[英]Only Allow POST Requests and Deny all other REQUEST_METHOD using .htaccess
[英]My .htaccess file rules not allowing all REQUEST_METHOD to execute
我意识到我下面从 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
如果我删除此规则,我的帖子将成功执行,但我不想使用文件扩展名。
我发现如果我要求它仅在 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.