限制 POST 请求服务器 [英] Restrict POST Request The Server

查看:30
本文介绍了限制 POST 请求服务器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想通过 .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.

推荐答案

该块只会阻止来自 127.0.0.1 以外的主机的 POST 请求,并且您将收到 403 Forbidden 响应.您可以尝试使用 mod_rewrite 并将 替换为:

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]   

如果您希望将发布请求发送到您网站的主页,请将最后一行中的 [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 /.

这篇关于限制 POST 请求服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆