6

Using the default cakephp htaccess file setup will not work on my domain when I want to install my Cakephp app in a subfolder, while everything works on localhost (xampp)

target => http://example.com/mycakeapp

Install needs 3 htaccess files:

root .htaccess

#.htaccess in root
<IfModule mod_rewrite.c>
   RewriteEngine on
   RewriteBase  /mycakeapp
   RewriteRule    ^$ app/webroot/    [L]
   RewriteRule    (.*) app/webroot/$1 [L]
</IfModule>

In app .htaccess

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

In webroot .htaccess

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

Following CakePHP's documentation, and Using these htaccess files, I get error500 results. Using RewriteBase / instead of /mycakeapp will throw 404 error page.

PHP is in 5.4 version. How can I solve this?

2 Answers 2

7

/dirCakePhp

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

/direCakePhp/app

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

/direCakePhp/app/webroot

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

Juste add '/' after RewriteRule,

And change PHP version in 1and1 hosting panel to => 5.2 Add date_default_timezone_set('Europe/Paris'); in core.php

4

Setup your rules like this:

.htaccess in DOCUMENT_ROOT

RewriteEngine on
RewriteBase /
RewriteRule (.*) mycakeapp/$1 [L]

.htaccess in DOCUMENT_ROOT/mycakeapp

RewriteEngine on
RewriteBase /mycakeapp/
RewriteRule (.*) app/webroot/$1 [L]

.htaccess in DOCUMENT_ROOT/mycakeapp/app

RewriteEngine on
RewriteBase /mycakeapp/app/
RewriteRule (.*) webroot/$1 [L]

.htaccess in DOCUMENT_ROOT/mycakeapp/app/webroot

RewriteEngine On
RewriteBase /mycakeapp/app/webroot/

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
1
  • Hi and thank you for your help. Now I can see my app. However this setup redirects mydomain.com/mycakeapp to mydomain.com as if my cakeapp was install in root folder. Actually, I do not need this redirection. How can I change this ?
    – angeltcho
    Dec 8, 2013 at 12:41

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.