18

I am trying to implement a REST protocol and have realized in trying to debug that my web server is disallowing the PUT request.

I have tested and confirmed this further by running:

curl -X PUT  http://www.mywebserver.com/testpage

Which for my web server gives back a 403 - Forbidden error.

The same happens for DELETE, where as for POST and GET everything is fine.

I am wondering if this is a common issue that those who use REST encounter and what the work-around might be?

Could I make a simple change to an .htaccess file? Or do I need to modify the protocol to set a hidden variable "_method" in the POST query string?

1 Answer 1

58

Often web servers will be configured to block anything except GET and POST since 99% of the time they're all that are needed and there have been problems in the past with applications assuming the requests were one of those two.

You don't say which server it is but, for example, you can tell Apache which methods to allow with the directive:

eg:

<Limit POST PUT DELETE>
  Require valid-user
</Limit>

It sounds like maybe some helpful sysadmin has used this to block non GET/POST

You could try an .htaccess with

<Limit GET POST PUT DELETE>
  Allow from all
</Limit>

(I'm not an expert at apache, this may not be exactly correct)

4
  • I'll add that this works even if you can't seem to find where those methods are disabled. - ahem, just found it, in Debian it's in userdir.conf.
    – bigstones
    Commented Sep 17, 2012 at 15:38
  • where should I put .htaccess file? Commented Feb 20, 2016 at 14:46
  • Limit directive docs: httpd.apache.org/docs/current/mod/core.html#limit Commented Jun 7, 2022 at 17:55
  • Typically, you'd put the htaccess file in the root webserver directory because "...the directives apply to that directory, and all subdirectories thereof." -docs.oracle.com/cd/B14099_19/web.1012/q20206/howto/… Commented Jun 7, 2022 at 18:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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