Implementing PUT and DELETE http requests in Apache 2 and cakephp.
Problem:
403 Forbidden error at the apache level when doing an Http PUT or DELETE request to cakephp.
404 File not found
Solution:
1 – Replace the regular htaccess rules in app\webroot\.htaccess:
RewriteEngine On
# Rewrite rules for PUT and DELETE Requests for RESTFUL requests
RewriteRule ^/?(api)/? index.php [NC]
RewriteCond %{REQUEST_METHOD} (PUT|DELETE)
RewriteRule .* index.php
# Normal cakephp rewrite rules
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?url=$1 [QSA,L]
2 – Add script tags inside your vhost configuration:
Script PUT /index.php Script DELETE /index.php
3 – Make sure your vhost documentroot is pointing to the correct webroot inside the cakephp app folder
DocumentRoot "C:\pathtowebserverwww\cakephp\app\webroot"
That’s it, in cakephp you can now parse DELETE and PUT commands
.
