11

How can I disable certain HTTP Methods (for example PUT or TRACE) and have Apache send an HTTP "405 Method not allowed".

I've tried the Limit and LimitExcept directives but they seem to send "403 Forbidden".

I have several vhosts - this should be across all of them, in the main httpd.conf.

14

It really seems that defining the error code is a bit harder than it should be.

However, one workaround MIGHT be using the mod_rewrite. Popped that one out of my head due the fact that in at least 99% of impossible-looking Apache problems mod_rewrite can provide its voodoo dance and solve your problem.

If everything else fails, try something like

RewriteEngine On
RewriteCond %{REQUEST_METHOD} !^GET [AND]
RewriteCond %{REQUEST_METHOD} !^POST 
RewriteRule .* /yourerrordocuments/405.html [R=405,L] 

I know that is probably not the nicest solution around, but it should kind of work...

| improve this answer | |
  • 1
    +1 Mod_rewrite voodoo solves all problems (for limited sets of all). – Chris S Nov 1 '10 at 12:56
  • 6
    Mod_rewrite also runs slow regex on every URL process, which slows the server down. Use with caution. – Marcin Nov 1 '10 at 13:20
  • Thanks - nice trick setting the response code with R=405. Was hoping there would be a better way so OPTIONS would report the right values but I guess it's not possible – Greg Nov 3 '10 at 16:46
  • What version of Apache/mod_rewrite supports the [AND] flag? I only see [OR] (and "and" being implicit): httpd.apache.org/docs/current/mod/mod_rewrite.html#rewritecond – asjo Jul 19 '18 at 21:49
4

For trace method you can add this

TraceEnable off

in your main configuration file

| improve this answer | |
2

To enable the rewrite engine, add the following:

 RewriteEngine On 

Please note that by default, rewrite configurations are not inherited across virtual servers. Add RewriteEngine On to each virtual host.

RewriteCond %{REQUEST_METHOD} ^(TRACE|TRACK|OPTIONS)
RewriteRule .* - [F]
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.