是否可以在某些url上阻止POST方法,例如
www.mydomain.com/dontposthere
www.mydomain.com/something/againdontposthere
如果您可以访问mod_rewrite,您可以检查REQUEST_METHOD
环境变量并将url重写为显示"您不允许发布"之类消息的另一个页面
创建消息:/var/www/noPost.php
You are not allowed to post to this page
然后使用.htaccess规则:
RewriteEngine On
RewriteCond %{REQUEST_METHOD} POST
RewriteCond %{REQUEST_URI} ^/dontposthere [OR]
RewriteCond %{REQUEST_URI} ^/something/againdontposthere
RewriteRule .* /noPost.php [L,QSA]
您可以创建一个文件/文件夹列表作为匹配条件,甚至可以创建一个正则表达式模式来匹配多个文件/文件夹。你只需要把[OR]
放在最后一个
除了写一个"noPost"页面,还可以直接返回一个带有F|forbidden标志的403响应:
RewriteCond %{REQUEST_METHOD} POST
RewriteCond %{REQUEST_URI} ^/dontposthere
RewriteRule .* - [F,L]