views:

49

answers:

1

Hi All:

I have a godaddy hosting account and having some problems with routing. The files are under /cakephp under the default /html folder. The full url is still showing instead of the desired www[dot]domain[dot]org Please help.

The current setup

/cakephp/.htaccess

RewriteEngine on RewriteBase /cakephp RewriteRule ^$ app/webroot/ [L] RewriteRule (.*) app/webroot/$1 [L]

/cakephp/app/.htaccess

RewriteEngine on RewriteBase /cakephp RewriteRule ^$ webroot/ [L] RewriteRule (.*) webroot/$1 [L]

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

+1  A: 

If I understand correctly, you can access your application from:

# http://example.com/cakephp/*   # normally served from html/cakephp/

... but instead you want URLs to display like this:

# http://example.com/*           # normally served from html/

The simplest option would be to move all the files and folders inside the cakephp directory up one level, as it's intended to work "out of the box", so the directory structure was like this:

# html/.htaccess               <- this file would then ...
# html/app
# html/app/.htaccess
# html/app/webroot             <- ... rewrite requests to here
# html/app/webroot/.htaccess
# html/cake

If you wish to keep the cakephp containing directory, then you will need to add your own .htaccess file to the html/ directory to tell Apache of your intentions. The structure would be like this:

# html/.htaccess               <- your .htaccess file goes here
# html/cakephp/.htaccess       <- it should look similar to this one
# html/cakephp/app
# html/cakephp/app/.htaccess
# html/cakephp/app/webroot     <- you need to rewrite requests to here
# html/cakephp/app/webroot/.htaccess
# html/cakephp/cake

The contents of which can be copied from the first CakePHP .htaccess file (as noted above) and altered slightly to produce the result you are after. Something like this:

RewriteEngine on
RewriteRule ^$   cakephp/app/webroot/   [L] # rewrites requests to example.com/
RewriteRule (.*) cakephp/app/webroot/$1 [L] # rewrites requests to example.com/*
deizel
Hi Deizel, thanks for the reply dude. I used the 2nd approach you recommended and now the homepage's URL is showing up as desired.But the controllers' pages are still showing the full URL, how should I edit the 3 .htaccess files in cakepho
jay
I did some testing and see what you mean. My answer above only really considered the Apache side of things (.htaccess + mod_rewrite). I (incorrectly) assumed that CakePHP would have determined the correct base path (ie. `/` instead of `/cakephp/`). Unfortunately, the code that works this out is buried in the dispatcher, which would mean editing the core (see this hack: http://kushaura.com/blog/view/name:Installing-CakePHP-in-a-Subdirectory). I therefore suggest using one of the supported installation types (http://book.cakephp.org/view/32/Installation), such as the first one suggested.
deizel