500 Errors With 1and1 Hosting/Apache 1.x

By Tim Mullin aka "tim_m"
When I uploaded a Cake-based site to a 1and1 shared hosting account, I got some mysterious 500 errors despite the site working perfectly on my dev machine.
I don't know if 1and1 is just weird or if it's an Apache 1.x issue but when I uploaded my Cake-based site from my dev computer where it was working perfectly running on Apache 2.x to my 1and1 account, I was getting 500 Internal Server Errors.

What worked for me was to change the three .htaccess files as follows:

root .htaccess file
Download code
<IfModule mod_rewrite.c>
   RewriteEngine on
   RewriteRule    ^$ /app/webroot/    [L]
   RewriteRule    (.*) /app/webroot/$1 [L]
</IfModule>


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


app/webroot/.htaccess
Download code
<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^(.*)$ /index.php?url=$1 [QSA,L]
</IfModule>


Note the added slashes. Also, this works for when Cake is the root folder of your website, i.e. you simply go to www.example.com, not www.example.com/path/to/cake.

If you do have your site in a sub-folder, like www.example.com/path/to/cake, use the following instead:

root .htaccess file
Download code
<IfModule mod_rewrite.c>
   RewriteEngine on
   RewriteRule    ^$ /path/to/cake/app/webroot/    [L]
   RewriteRule    (.*) /path/to/cake/app/webroot/$1 [L]
</IfModule>


app/.htaccess
Download code
<IfModule mod_rewrite.c>
    RewriteEngine on
    RewriteRule    ^$    /path/to/cake/app/webroot/    [L]
    RewriteRule    (.*) /path/to/cake/app/webroot/$1    [L]
 </IfModule>


app/webroot/.htaccess
Download code
<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^(.*)$ /path/to/cake/app/webroot/index.php?url=$1 [QSA,L]
</IfModule>


Hope this saves someone days of frustration.

Comments 529

CakePHP team comments Author comments

Comment

1 Use RewriteBase insted

It is more common practice to use RewriteBase instead:
root .htaccess

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


And this way, you can just change the RewriteBase quickly to /path/to/cake later or back again and you only had to edit one line per file, instead of two (or more for other applications). Unless you disagree, I think you should reflect this in your article.
posted Fri, Sep 21st 2007, 09:22 by John Hanauer

Comment

2 probably

You're probably right, but I tried for about 2 days to get this working (part of that time was an issue with a separate rewrite rule though), I know I tried something using RewriteBase but it didn't work. It's completely possible I didn't have it set correctly. When I finally got it working I was just happy it worked and didn't want to screw around with it anymore.
posted Sat, Sep 22nd 2007, 18:04 by Tim Mullin

Comment

3 Thanks

Thanks, that fixed a really annoying problem for me.
posted Sat, Nov 17th 2007, 05:24 by Matt Newboult

Comment

4 Frustrating

I'm on dreamhost and getting these errors. Setting the rewriteBase didn't help either. This is so frustrating!!!
posted Sun, Dec 9th 2007, 15:56 by Richard Savage

Comment

5 MultiViews Vs FollowSymlinks

You're probably right, but I tried for about 2 days to get this working (part of that time was an issue with a separate rewrite rule though), I know I tried something using RewriteBase but it didn't work. It's completely possible I didn't have it set correctly. When I finally got it working I was just happy it worked and didn't want to screw around with it anymore.

I agree that you did not want to screw things up again! But it may help other or may you be decide, after all, to get rid of editing multiple lines. Try this:
In you appache config (httpd.conf) file try something like this: Options Indexes FollowSymlinks. Change nothing else.
posted Mon, Apr 14th 2008, 00:44 by Shahzad Anees

Login to Submit a Comment