限制POST请求的服务器服务器、POST

2023-09-02 00:44:57 作者:大萌货

我要限制通过 .htacces 来自其他服务器的所有POST请求 如果他们试图张贴任何来自其他服务器的事情,他们会重定向到主页或404等。 我想这

I want to restrict all POST request that comes from other server via .htacces if they try to post any from other server thing they will get redirected to home page or 404 etc. I tried this

<Limit POST>  
order deny,allow  
deny from all 
allow from 127.0.0.1
</Limit> 

注: - GET请求,允许来自所有服务器。只有阻止POST请求。

Note:- GET request are allowed from all servers. Only to block POST requests.

推荐答案

这是块只会prevent员额从主机127.0.0.1以外的请求,你会得到一个403禁止响应。你可以尝试使用mod_rewrite和替换&LT;极限&GT;

That block will only prevent POST requests from hosts other than 127.0.0.1, and you will get a 403 Forbidden response. You could try using mod_rewrite and replace the <LIMIT> with:

RewriteCond %{REQUEST_METHOD} POST

# allow the server to POST to itself
RewriteCond %{REMOTE_ADDR} !127.0.0.1   

# allow POST from trusted users
RewriteCond %{REMOTE_ADDR} !123.456.789.123   

# send all other post requests to 403 forbidden
RewriteRule ^ / [F]   

如果您需要preFER到post请求发送到您的网站的主页上,而不是替换 [F] 的最后一行[R,L]

If you would prefer to send post request to the home page of your site instead replace [F] in the last line with [R,L]

您会替换 / 替换为您的主页是,如果它不只是 /

You'd replace the / with where your "home page" is if it isn't just /.