I'm about at my wits' end with mod_rewrite problems trying to deploy a CakePHP app on shared hosting with Apache 1.3. Despite using the default .htaccess files I seem to be plagued by rewrite loops and lots of trial and error hasn't really got me anywhere.

On the server my app is installed in:


Apache accesses this directory via a subdomain symlink:


My CakePHP app is on the root inside 'testing', with a dir structure like:


The base .htaccess looks like (as per the defaults):

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

The webroot .htaccess looks like:

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

This all seems to work on my laptop (with Apache 2.2) but gives me errors on the server because it seems to be endlessly rewriting the request. If I access the any URI, base or not, I get a 403 error with this in the Apache error log:

File name too long: access to /home/www/hosts/testing.mydomain.com/webroot/home/www/hosts/testing.mydomain.com/webroot/home/www/hosts/testing.mydomain.com/webroot/home/www/hosts/testing.mydomain.com/webroot/home/www/hosts/testing.mydomain.com/ [REPEAT FOR A LONG TIME...]

Can anyone see anything that'd lead to the endlessly appended rewrite here? I've tried a bunch of things, such as adding RewriteConds to test the uri doesn't already contain 'webroot' but nothing seems to work. I'm willing to bet it's something obvious though!



Must get out of the habit of answering my own questions but the act of posting to SF seems to break the logjam. Apparently what was needed was adding to each .htaccess respectively:

RewriteBase /
RewriteBase /webroot

Still not sure particularly why those directives are needed, but I suspect it's something to do with the subdomain "testing" directory relates to the document root.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.