1
votes

I have a cakephp installation in root Folder say caketest.com I want run another cakephp installation in a sub folder with a sub-domain say subdomain.caketest.com

Problem I am facing is when I access subdomain.caketest.com then all the controllers of caketest.com are overriding controllers of subdomain.caketest.com lets say app controller of outer cake is executing instead of inner (but you know I am running URL for inner cake)

So to overcome this I tried giving rewrite base to inner cakehphp .htacess

My directory structure is

 public_html
  app
     webroot
     controllers
  ...and all cakephp folders
     index.php -of cake-
     .htaccess

  newyork -folder that contains another cakephp project 
            all cakephp folders and files

I tried this in .htaccess inside newyork folder and get internal server error

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

Thanks Surinder

1
Did you try plugins?SaidbakR
No. I want to do this with htaccess and I know that it is possible with that. just don't know how..Surinder

1 Answers

0
votes

On my website that I run CakePHP, I have the following directory structure:

public_html
   webroot
   controllers
   ...and all cakephp folders
   index.php -of cake-
   .htaccess
   Hosts -folder at which subdomains folders-
       dir -folder that contains another cakephp project called dir-
            all cakephp folders and files

My primary domain runs Cakephp app, and dir.mydomain.com runs another CakePHP app.

The following is the .htaccess in public_html

# Turn off the ETags
Header unset ETag
FileETag None

# Turn off the Last Modified header except for html docs
<FilesMatch "\.(ico|pdf|flv|jpg|jpeg|png|gif|js|css|mp3)$">
Header unset Last-Modified
</FilesMatch>
<FilesMatch "\.(ico|pdf|flv|jpg|jpeg|png|gif|js|css|swf|mp3)$">
Header set Expires "Thu, 15 Jan 2015 20:00:00 GMT"
</FilesMatch>
<FilesMatch "\.(ico|pdf|flv|jpg|jpeg|png|gif|js|css|swf|mp3)$">
   Header set Cache-Control "max-age=31449600"
 </FilesMatch>


# Use PHP5.3 as default
AddHandler application/x-httpd-php54 .php
#Deny from mydomain.com/Host/
Redirect /Host/dir/ http://dir.mydomain.com/

<IfModule mod_rewrite.c>


#RewriteRule .* http://%{SERVER_NAME}%{REQUEST_URI} [R,L]
    RewriteEngine on
#RewriteCond %{HTTPS} =on
#RewriteBase /~username/

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

AddType audio/mpeg mp3
AddType text/xml xml

The following is .htaccess of public_html/webroot and public_html/Host/dir

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

The following is .htaccess of public_html/Host/dir/webroot

Options -Multiviews -Indexes +SymLinksIfOwnerMatch
<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
DirectorySlash Off
RewriteCond %{HTTP_HOST} !^dir.mydomain.com$ [NC]
RewriteRule ^(.*)$ http://dir.mydomain.com/$1 [L,R=301]

RewriteRule ^/?searches/index/(.*)$ /searches/$1 [R=301,L]
RewriteRule ^(.*)/page:1$ /$1 [R=301,L] 
RewriteRule ^(.*)\/(\?.*)?$ $1$2 [R=301,L]
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f

    RewriteRule ^(.*)$ index.php?url=$1 [QSA,L]

</IfModule>
AddType audio/mpeg mp3
AddType text/xml xml

By the way my shared hosting supports creating sub-domains from the Cpanel. Also I separate the CakePHP core from the application structure and defined in webroot/index.php as follows:

if (!defined('CAKE_CORE_INCLUDE_PATH')) {
        define('CAKE_CORE_INCLUDE_PATH', DS.'home2'.DS.'username'.DS.'libs'.DS.'cakephp');
    }