23

I'm trying to get a CakePHP application to work. For this, I've set up a brand new Debian installation, updated the configuration and put everything in /var/www, which has the following content:

app
cake
.htaccess
index.php
vendors

The .htaccess file contains the following:

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

If I access my virtualhost (http://myhost/) I see the correct page. But even the JavaScript loaded with src="/js/validate.js" fails (it's located within /var/www/app/webroot/js/validate.js):

[Wed Aug 26 15:45:12 2009] [error] [client 10.7.10.52] Request exceeded the limit of 10 internal redirects due to probable configuration error. Use 'LimitInternalRecursion' to increase the limit if necessary. Use 'LogLevel debug' to get a backtrace.
[Wed Aug 26 15:45:12 2009] [debug] core.c(3063): [client 10.7.10.52] r->uri = /webroot/webroot/webroot/webroot/webroot/webroot/webroot/webroot/webroot/webroot/js/prototype.js
[Wed Aug 26 15:45:12 2009] [debug] core.c(3069): [client 10.7.10.52] redirected from r->uri = /webroot/webroot/webroot/webroot/webroot/webroot/webroot/webroot/webroot/js/prototype.js
[Wed Aug 26 15:45:12 2009] [debug] core.c(3069): [client 10.7.10.52] redirected from r->uri = /webroot/webroot/webroot/webroot/webroot/webroot/webroot/webroot/js/prototype.js
[Wed Aug 26 15:45:12 2009] [debug] core.c(3069): [client 10.7.10.52] redirected from r->uri = /webroot/webroot/webroot/webroot/webroot/webroot/webroot/js/prototype.js
[Wed Aug 26 15:45:12 2009] [debug] core.c(3069): [client 10.7.10.52] redirected from r->uri = /webroot/webroot/webroot/webroot/webroot/webroot/js/prototype.js
[Wed Aug 26 15:45:12 2009] [debug] core.c(3069): [client 10.7.10.52] redirected from r->uri = /webroot/webroot/webroot/webroot/webroot/js/prototype.js
[Wed Aug 26 15:45:12 2009] [debug] core.c(3069): [client 10.7.10.52] redirected from r->uri = /webroot/webroot/webroot/webroot/js/prototype.js
[Wed Aug 26 15:45:12 2009] [debug] core.c(3069): [client 10.7.10.52] redirected from r->uri = /webroot/webroot/webroot/js/prototype.js
[Wed Aug 26 15:45:12 2009] [debug] core.c(3069): [client 10.7.10.52] redirected from r->uri = /webroot/webroot/js/prototype.js
[Wed Aug 26 15:45:12 2009] [debug] core.c(3069): [client 10.7.10.52] redirected from r->uri = /webroot/js/prototype.js
[Wed Aug 26 15:45:12 2009] [debug] core.c(3069): [client 10.7.10.52] redirected from r->uri = /js/prototype.js
[Wed Aug 26 15:45:12 2009] [debug] mod_deflate.c(632): [client 10.7.10.52] Zlib: Compressed 649 to 405 : URL /webroot/webroot/webroot/webroot/webroot/webroot/webroot/webroot/webroot/webroot/js/prototype.js

Hence my question: what is the correct .htaccess required for CakePHP?

Many, many thanks!

Moe Far
  • 2,742
  • 2
  • 23
  • 41
MrG
  • 5,277
  • 17
  • 48
  • 66
  • 1
    Which directory do you have for the site root in your apache config? It should be /var/www/app/webroot - that may fix your problem. – brettkelly Aug 26 '09 at 13:48
  • @inkedmn: thank you, it would be /var/www - but the error was because I was using just one .htaccess, not 3, as I just found out. Thank you! – MrG Aug 26 '09 at 13:59

5 Answers5

65

The answer is that there are 3 different .htaccess files:

/var/www/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>

/var/www/app/.htaccess

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

/var/www/.htaccess

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

It's been my fault, everything is listed on the CakePHP site. Thanks to everyone!

Sadikhasan
  • 18,365
  • 21
  • 80
  • 122
MrG
  • 5,277
  • 17
  • 48
  • 66
3

The correct .htaccess is the default:

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

You have to add this in "/etc/apache2/sites-enabled/default":

<Directory /var/www>
  Options Indexes FollowSymLinks MultiViews
  AllowOverride All
  Order allow,deny
  allow from all
</Directory>

if section already exists change AllowOverride None to AllowOverride All

riotera
  • 1,613
  • 9
  • 14
0

CakePHP has only one .htaccess file inside webroot directory. No need more .htaccess files. You must set app/webroot as your DOCUMENT_ROOT.

Ali Farhoudi
  • 5,350
  • 7
  • 26
  • 44
0

Removing .htaccess from main file may solve this problem. It worked for me(need not remove from webroot)

Techie
  • 44,706
  • 42
  • 157
  • 243
0

If allowed by your provider you may put all in the httpd.conf file as follow

<Directory /var/www>
  Options Indexes FollowSymLinks MultiViews
  AllowOverride All
  Order allow,deny
  allow from all
  <IfModule mod_rewrite.c>
      RewriteEngine on
      RewriteRule    ^$    webroot/    [L]
      RewriteRule    (.*) webroot/$1    [L]
  </IfModule>
</Directory>

And so on for others directories...

MUY Belgium
  • 2,330
  • 4
  • 30
  • 46