如何在htaccess中的某个url上阻止post方法

Nov*_*ato 3 php apache .htaccess

是否可以在某些网址上阻止POST方法

www.mydomain.com/dontposthere
www.mydomain.com/something/againdontposthere
Run Code Online (Sandbox Code Playgroud)

在htaccess?

Jon*_*uhn 8

如果您有权访问mod_rewrite,则可以检查REQUEST_METHOD环境变量并将URL重写到另一个页面,该页面显示一条消息,上面写着"您不允许发布"的消息

创建一个包含以下消息的页面: /var/www/noPost.php

You are not allowed to post to this page
Run Code Online (Sandbox Code Playgroud)

然后像这样使用.htaccess规则:

RewriteEngine On

RewriteCond %{REQUEST_METHOD} POST
RewriteCond %{REQUEST_URI} ^/dontposthere [OR]
RewriteCond %{REQUEST_URI} ^/something/againdontposthere
RewriteRule .* /noPost.php [L,QSA]
Run Code Online (Sandbox Code Playgroud)

您可以创建文件/文件夹列表作为匹配条件,甚至可以创建正则表达式模式以匹配多个文件/文件夹.[OR]除了最后一个,你只需要放置.