Tags

, , ,


Sometime we may need to put cakephp in a sub directory insted of document root directory, and we need to get the site from root.
Our document root directory is /httpdocs/ and we put the cakephp inside it /httpdocs /cake_sub/ and we want access the site from http://www.my-domain-name.com not http://www.my-domain-name.com/cake_sub

1. In this case we need to create a .htaccess file and put it to /httpdocs/ and the content is as follow

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

So we need to on the RewriteEngine Now we need to edit the .htaccess files from the following locaiton

  • cake_sub/
  • cake_sub/app
  • cake_sub/webroot

2. Need to edit the .htaccess from /httpdocs/cake_sub as following


<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /cake_sub/
RewriteRule    ^$ app/webroot/    [L]
RewriteRule    (.*) app/webroot/$1 [L]
</IfModule>
3. Need to edit the .htaccess from /httpdocs/cake_sub/app as following
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /cake_sub/app/
RewriteRule    ^$    webroot/    [L]
RewriteRule    (.*) webroot/$1    [L]
</IfModule>

4. Need to edit the .htaccess from /httpdocs/cake_sub/app/webroot as following

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


Done, It worked with me and hope it’ll work with you too. I just put the document root httpdocs and sub directory name as an example.

Advertisement