0

How to disable HEAD Method using .htaccess ?

I'm looking for a solution such that the GET/POST and other such donot get affected by this .htaccess command.

I've already disabled Trace using httpd config and have gone through various answers on stackoverflow but none of them are precise to my requirement.

Nalin Raturi
  • 1
  • 1
  • 5

2 Answers2

1

This allows GET and POST and disable HTTP/1.0. It also disables proxy requests:

    RewriteEngine on
    RewriteCond %{THE_REQUEST} !^(POST|GET)\ /.*\ HTTP/1\.1$ 
    RewriteRule .* - [F]
J_P
  • 761
  • 8
  • 17
  • 1
    Your solution allows only GET & POST but what about other methods such as PUT,DELETE,TRACE,OPTIONS. My intention is to dis-allow only HEAD Method and not affecting other Methods. – Nalin Raturi Feb 09 '18 at 12:25
  • This blocks all requests except POST and GET… which is not what OP is asking for. Besides, RewriteCond put a bit more load on the server compared to a simple “Limit” rule. – e-sushi Dec 04 '19 at 05:55
0

To exclusively block HEAD requests via .htaccess, you can simply “Limit” them like this:

    <Limit HEAD>
    Order Deny,Allow
    Deny from All
    </Limit> 
e-sushi
  • 13,786
  • 10
  • 38
  • 57