Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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:

/home/www/myusername/testing

Apache accesses this directory via a subdomain symlink:

/home/www/hosts/testing.mydomain.com/

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

/home/www/myusername/testing/
    webroot/
    controllers/
    etc...        

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

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

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]
</IfModule>

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!

Thanks.

share|improve this question

1 Answer 1

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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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