简体   繁体   English

拒绝除带有htaccess的POST以外的所有方法

[英]Deny all methods except POST with htaccess

I am writing rest api application in php and I want to deny access to my host all methods except Post. 我正在用php编写rest api应用程序,但我想拒绝对除Post之后的所有方法的访问。 POST method should work only, others should throw Access denied error. POST方法应仅起作用,其他方法应抛出“访问被拒绝”错误。 How do I do that with. 我该怎么做。 htaccess? htaccess?

You can use apache's LimitExcept Directive to allow or deny requests 您可以使用apache的LimitExcept指令来允许或拒绝请求

Restrict access controls to all HTTP methods except the named ones 将访问控制限制为除命名方法外的所有HTTP方法

<LimitExcept POST>
 order deny,allow
 deny from all
</LimitExcept>

尝试在开始时将其添加到.htaccess

Header add Access-Control-Allow-Methods "POST"

You can use mod-rewrite to allow only POST requests. 您可以使用mod-rewrite仅允许POST请求。

At the top of your htaccess ,put the following rule: 在htaccess的顶部,输入以下规则:

RewriteEngine on

#if Request method isn't "POST"
RewriteCond %{REQUEST_METHOD} !POST
#redirect the request to 403 error
RewriteRule .* - [R=403,L]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM