Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to configure htaccess file for Cake 2.3.x on 1and1 shared hosting

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?

like image 422
angeltcho Avatar asked Dec 07 '13 13:12

angeltcho


2 Answers

/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

like image 117
eclaude Avatar answered Nov 07 '22 09:11

eclaude


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]
like image 39
anubhava Avatar answered Nov 07 '22 08:11

anubhava