Viewed   111 times

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!

 Answers

2

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!

Saturday, August 13, 2022
4

It seems to be a bug in cakephp. In cakePHP 1.3+ the themed view assets have been moved from app/webroot/themed/themeTitle to app/views/themed/themeTitle/webroot.

According to CakePHP 1.3 documentation you are able to restore the old place (i.e. in the main webroot) of the themed static assets by creating app/webroot/theme/themeTitle

Linking to static assets is slightly different from 1.2. You can still use the existing app/webroot/themed and directly link to those static files. It should be noted that you will need to use the full path to link to assets in app/webroot/themed. If you want to keep your theme assets inside app/webroot it is recommended that you rename app/webroot/themed to app/webroot/theme. This will allow you to leverage the core helper path finding. As well as keep the performance benefits of not serving assets through PHP.

So, what I have done for solve this issue is to copying all files in app/views/themed/slate/webroot to app/webroot/theme/slate

The following screen shot is from FireFox Firebug that shows an image file get the expire after one year in seconds:

Sunday, August 14, 2022
4

Seems like the solution that worked for me was to edit /etc/apache2/users/username.conf and add this at the top:

DocumentRoot "/Users/username/Sites"

And the default cakePHP download now runs ok.

Friday, December 2, 2022
4

Finally after 1 week (between other tasks) I solved this!

Here is my solution:

/public_html/.htaccess

<IfModule mod_rewrite.c>
    RewriteEngine on
    RewriteBase /

    # http|https www to non-www
    RewriteCond %{HTTP_HOST} ^www.(.*)$ [NC]
    RewriteCond %{HTTPS}s ^on(s)|
    RewriteRule ^(.*)$ http%1://domain.com/$1 [R=301,L]

    # redirect all subdomains
    RewriteCond %{HTTP_HOST} !^domain.(.*)$ [NC]
    RewriteCond %{HTTPS} on
    RewriteRule ^(.*)$ /%{HTTP_HOST}/$1 [NC,L,NS]

    RewriteCond %{HTTP_HOST} ^domain.(.*)$ [NC]
    RewriteRule ^$ app/webroot/    [L]
    RewriteCond %{HTTP_HOST} ^domain.(.*)$ [NC]
    RewriteRule (.*) app/webroot/$1 [L]
</IfModule>

/public_html/sub1.domain.com/.htaccess

<IfModule mod_rewrite.c>
    RewriteEngine on
    RewriteBase /

    RewriteCond %{REQUEST_URI} ^/%{HTTP_HOST}
    RewriteRule ^%{HTTP_HOST}(.*)$ /$1

    RewriteCond %{HTTPS} on
    RewriteRule ^$ %{HTTP_HOST}/app/webroot/    [L]
    RewriteCond %{HTTPS} on
    RewriteRule (.*) %{HTTP_HOST}/app/webroot/$1 [L]

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

/public_html/sub1.domain.com/app/.htaccess

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

/public_html/sub1.domain.com/app/webroot/.htaccess

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /

    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{HTTPS} on
    RewriteRule ^(.*)$ %{HTTP_HOST}/index.php [QSA,L]

    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{HTTPS} !on
    RewriteRule ^(.*)$ index.php [QSA,L]
</IfModule>

And finally the most important!

/public_html/sub1.domain.com/app/webroot/index.php

On the bottom: $Dispatcher = new Dispatcher(); changed to: $Dispatcher = new Dispatcher('');

Saturday, August 6, 2022
 
kylotan
 
3

Your code is not quite right. See below.

RewriteEngine On
RewriteCond %{HTTP_HOST} ^domain.com$ [NC]
RewriteRule ^.*$ http://www.domain.com%{REQUEST_URI} [R=301,L] # <-- Mind the 'L'!

RewriteRule ^$ webroot/    [L]
RewriteRule (.*) webroot/$1 [L]
Thursday, December 8, 2022
 
Only authorized users can answer the search term. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :