I am building a RESTFUL API and need to get Apache to accept PUT requests. Whenever I put to a URL, I am getting a 403 Forbidden
error.
curl -X PUT api.example.com/api/foo
I have tried to add the following to my Virtual Directory (To no avail):
<Limit GET POST PUT DELETE HEAD OPTIONS>
Order allow,deny
Allow from all
</Limit>
<LimitExcept GET POST PUT DELETE HEAD OPTIONS>
Order deny,allow
Deny from all
</LimitExcept>
What other config settings might be causing this?
EDIT
I am re-writing my URL's, all get re-written to index.php as follows:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !\.
RewriteRule ^(.*)$ /api/index.php/$1 [L,QSA]
Add this to the .htaccess file in this folder
-- For Apache 2.2
-- For Apache 2.4
Note: you can remove methods which you dont want
At least with the last Apache's version (2.4.38) with modsecurity enabled, only these methods are allowed by default: GET HEAD POST OPTIONS
When a PUT request is made the error log of Apache2 returns this message:
The best way to solve it is changing this policy in modsecurity, so edit the file "/etc/modsecurity/crs/crs-setup.conf" and uncomment the following lines adding PUT as allowed:
Edit:
Add this to your Apache conf:
This assumes your actual handler script is called
index.php
and it's located on/api
.