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');
}