Cakephp .htaccess problem (Internal Server Error)

I came across this Internal Server Error twice in my experience while working with cakephp. Once it was due to the database.php file, which was not modified after uploading. It was still referring to localhost db with login credentials. After I modified that it worked fine, was pretty easy.

But the second time, when I hit with this problem, I had to work for half a day to find a solution to this. This time it was because of the .htaccess file. This is what I had to do:
<IfModule mod_rewrite.c>
   RewriteEngine on
   RewriteRule    ^$ /app/webroot/    [L]
   RewriteRule    (.*) /app/webroot/$1 [L]
</IfModule>

I had to add a  '/' before the app folder. And similarly in the webroot folder I had to add a '/' in front of index.php file. This will work fine if you have only one app folder. But the next problem I had to face was, that I had another app folder which was renamed to admin for admin side scripts and it was sharing the same cake folder. This is how I had to fix this problem:

In the app folder I had one .htaccess file with the following piece of code:

<IfModule mod_rewrite.c>
    RewriteEngine on
    RewriteRule    ^$    /admin/webroot/    [L]
    RewriteRule    (.*) /admin/webroot/$1    [L]
 </IfModule>

And under webroot I had another .htaccess file with this following piece of code:
<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^(.*)$    /admin/webroot/index.php?url=$1 [QSA,L]
</IfModule>

This was good enough for my site to be up and running. Later I was hit by another problem which was:

I had a login form, and after login, it has to redirect to a page. During the process it was giving a 200 OK error and showing the source code of the file instead of executing it. As far as I understood, the redirect in cakephp was trying to find in the cache (as cake is famous for its strong caching), and failing to find the file. So, I removed the $this->redirect tag and instead wrote header() function of PHP and it worked. Voila, I am writing all this for my sake and for others who may hit with similar kind of problems.



About this blog

This blog is all about PHP and related frameworks. It reveals my little experiences, the challenges I faced in my career, my explorations and my innovations. I hope it benefits me and others too who might face these challenges in their career. Have a nice time reading the blog. Enjoy.

About Me

Hi, my name is Hima. I am an experienced programmer in PHP and related frameworks. I live in Hyderabad, India.
Copyright © 2010 - My PHP Tips & Tutorials. Powered by Blogger.. Powered by Blogger.