gpt4 book ai didi

php - 如何在 htaccess 中阻止某些 url 上的 post 方法

转载 作者:可可西里 更新时间:2023-11-01 00:09:36 26 4
gpt4 key购买 nike

是否可以在某些 url 上阻止 POST 方法,例如

www.mydomain.com/dontposthere
www.mydomain.com/something/againdontposthere

在 htaccess 中?

最佳答案

如果您有权访问 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] 放在最后一个之后。

关于php - 如何在 htaccess 中阻止某些 url 上的 post 方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17114379/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com