Search code examples
.htaccesscakephproutesshared-hostingaddon-domain

Links are broken when installing CakePHP on shared hosting


I have set up CakePHP on shared hosting, within a sub-directory (cakeDomain). Using htaccess in the root directory (mainDomain), I have pointed another domain to it (cakeDomain), like so:

# /.htaccess
# cakeDomain redirect rules
RedirectMatch 301 ^/cakeDomain/$ http://cakeDomain.com/
# handle domain root and skip subfolders
RewriteCond %{HTTP_HOST} cakeDomain.com
RewriteCond %{REQUEST_URI} !^/cakeDomain/
RewriteCond %{REQUEST_URI} \..+$
RewriteRule ^(.*)$ cakeDomain/$1 [L]

# add trailing slash to subfolders (eg abc to: abc/)
RewriteCond %{HTTP_HOST} cakeDomain.com
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} [^/]$
RewriteRule ^(.*)$ $1/ [L,R=301]

# handle files in subfolders
RewriteCond %{HTTP_HOST} cakeDomain.com
RewriteCond %{REQUEST_URI} !^/cakeDomain/
RewriteRule ^(.*)$ cakeDomain/$1/ [L]

RewriteCond %{HTTP_HOST} www.mainDomain.com/cakeDomain/
RewriteRule %{HTTP_HOST} www.cakeDomain.com [L]

Visiting mainDomain.com/cakeDomain correctly redirects you to cakeDomain.com

CakePHP's files are stored as so:

/cakeDomain/app/...
/cakeDomain/lib/...
/cakeDomain/...
etc.

Visiting cakeDomain.com brings up the correct front page but all of the links have the installed directory prepended to them:

cakeDomain.com/cakeDomain/controller/action/param1

Instead of:

cakeDomain.com/controller/action/param1

Any ideas how to fix this?

Please note, from my many searches, that it appears many people immediately suggest virtual hosts. This is not an option here; my hosting is a virtual host. I presume this solution requires htaccess and/or routing tricks. Thank-you in advance for any help you can provide.


Solution

  • Basically, you're putting website B (Cake) inside the public web directory of website A (Maindomain).

    I would REALLY discourage you to do so because this way all 'private' CakePHP directories are also inside your public web directory (for example cakeDomain/app/tmp/logs/error.log). Please check properly if those locations are secured properly

    Dou you have access to the directories 'outside' your public webfoot?

    Having said that, this may be of help: http://cookingwithcakephp.blogspot.nl/2008/04/installing-cakephp-into-subdirectory.html