![](/img/trans.png)
[英]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.