500 Errors With 1and1 Hosting/Apache 1.x

by 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

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


app/.htaccess

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

app/webroot/.htaccess

<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

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


app/.htaccess

<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

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

Report

More on Tutorials

Advertising

Comments

  • kostasz posted on 04/12/11 03:11:07 PM
    Thank you very much for your post! We have also experienced problems with setting up Cake on 1&1 (500 errors). We have fixed this by also adding the option "Options +FollowSymLinks" inside each IfModule mode_rewrite.c wrapper.

    root .htaccess file contents

    Options +FollowSymLinks
    RewriteEngine on
    RewriteBase /
    RewriteRule ^$ app/webroot/ [L] RewriteRule (.*) app/webroot/$1 [L]

    app/.htaccess

    Options +FollowSymLinks
    RewriteEngine on
    RewriteBase /
    RewriteRule ^$ /webroot/ [L] RewriteRule (.*) /webroot/$1 [L]

    app/webroot/.htaccess

    Options +FollowSymLinks
    RewriteEngine On
    RewriteBase /
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^(.*)$ /index.php?url=$1 [QSA,L] php_flag magic_quotes_gpc Off



  • giantlimes posted on 03/17/11 04:44:21 PM
    I have setup a subdomain pointing to a new subdirectory.

    If I go to subdomain.mydomain.com I get a 500 error

    If I go to www.mydomain.com/subdirectory it works.

    example:

       RewriteEngine on
       RewriteBase /dev/
       RewriteRule    ^$ app/webroot/    [L]
       RewriteRule    (.*) app/webroot/$1 [L]
  • posted on 03/15/11 06:46:58 PM
    Hi..

    can someone help me.. I tried it.. but for me it doesn't work... also I tried use RewriteBase, both cases the same result.. the 500 server error don't go away...

    thanks in advanced..

  • saavedrajj posted on 07/04/10 06:32:58 PM
    Almost 3 years later, your setup still working. Thank you VERY MUCH
  • MaxProWeb posted on 03/31/10 04:35:48 PM
    thanks. it is helpful

    I use other way.

    if project in directory domain.com/project/ <- this is root of the project then in .htaccess you should add

    RewriteBase /project/
    also don not forget about php5 !
    to switch on add in .htaccess

    AddType x-mapp-php5 .php
  • caryme posted on 12/18/09 06:56:19 PM
    My application is hosted on webfaction and this fix just worked for me. Thanks!
  • kienpham2000 posted on 09/30/09 07:36:29 PM
    I was trying to get my site to work for several hours with no luck until I found your article :)

    Thank you :)

    - Kien
  • hernanc posted on 07/07/09 10:33:28 AM
    Hi There,
    I'm trying to upload something to www.example.com/subdir, using 1and1.
    If I go to: http://www.example.com/subdir (without trailing slash) I get
    this error:
    Error: KundenController could not be found.
    Error: Create the class KundenController below in file: app/controllers/kunden_controller.php

    But if I add the trailing slash everything works fine. And in my local environment works flawlessly. I'm kind of clueless. Any ideas?

    And what's that Künden Controller?

    Thanks in advance!
  • gr8whitesavage posted on 12/09/07 03:56:20 PM
    I'm on dreamhost and getting these errors. Setting the rewriteBase didn't help either. This is so frustrating!!!
  • igorisking posted on 11/17/07 05:24:50 AM
    Thanks, that fixed a really annoying problem for me.
  • glite posted on 09/21/07 09:22:17 AM
    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.
    • tim_m posted on 09/22/07 06:04:54 PM
      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.
      • shahzadanees posted on 04/14/08 12:44:39 AM
        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.
login to post a comment.