Apache 2 – cakephp Restful PUT DELETE

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 :) .

Hello world! Thats how it first started, way back when!

First post, first post!!!

Oh well it had to happen some day… I had been delaying this for so long, finally it struck me, and so it starts – my own personal blog on the web.

Without making any compromises, I Hopefully … will post and share some of my thoughts and ramblings regularly, as well as make this a place for discussing technology, coding, social life, gaming… etc!

FYI: I am not a versed blogger so please bear with me if my writing is a tad lacking.

Thanks!!