Limit POST Request

I want to limit all POST requests coming from another server via .htacces if they try to publish any information from another server, they will be redirected to the home page or 404, etc. I tried this

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

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

+6
source share
1 answer

This block will only prevent POST requests from hosts other than 127.0.0.1, and you will receive a 403 Forbidden response. You can try using mod_rewrite and replace <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] 

If you prefer to send a mail request to the home page of your site, instead of [F] , the last line should be [R,L]

You would replace / with where your "homepage" is, if it's not just / .

+13
source

Source: https://habr.com/ru/post/920981/


All Articles