1
votes

I am working on a CakePHP application. When I uploaded it to my host's public_html directory I have created a subdirectory for it.

So right now the structure is like that: domain.com/subdircake/.

I have included a .htaccess file in the public_html root, and I have changed the index.php in the webroot folder to point the subdirectory.

I don't know if it is a routing issue inside the cakeapp or a mod_rewrite issue because of a wrong .htaccess configuration, but what happens is this.

  1. I can access the domain and it shows the home page for the app.
  2. The links are pointing to domain.com/subdircake/action instead of domain.com/action.
  3. When I am forcing the url to be domain.com/action it works and this leaves me stressed because I don't know why.

So I think it has to be some rewrite issue but I don't have any clues.

Anyone any idea?

4
Is another website already hosted in that public_html directory? Do you also have access to the directories 'outside' the public_html directory? Just to inform what options would apply to you.thaJeztah
Nope, this is the only site. I don't have access outside the public_html directory.Kornel

4 Answers

5
votes

The reason why going to domain.com/action works is that your .htaccess solution was effective - it is indeed rewriting the URL to the right location. However, CakePHP's routing system is unaware of the changes you made to the default rewriting script, which causes the HTML Helper to generate links that still point to the place they would without you editing the .htaccess file.

The first solution that comes to mind is changing your App.base configuration; in Config/bootstrap.php, add this line:

Configure::write('App.base','/');

And see if that helps. I would recommend testing the site thoroughly after changing that setting, though - many CakePHP features use it, and the results could be unexpected.

0
votes

Do you use userdir mod ?

If you do so, you have to edit the 3 cake .htaccess (located in the root of your cake folder, in your app/ folder and in your app/webroot/ folder, and add one of these line just after the RewriteEngine On line:

#.htaccess :
RewriteBase /~username/

#app/.htaccess :
RewriteBase /~username/app

#app/webroot/.htaccess :
RewriteBase /~username/app/webroot

Replace username by your username, but don't forget the ~

If you cake folder is in a subdir, it will be /~username/subdir/...

0
votes

Put the contents of the webroot directory in your public_html folder.

Then change index.php (in webroot/public_html, not in cake's app dir) the following lines

if (!defined('ROOT')) {
    define('ROOT', 'subcakedir');
}

/**
 * The actual directory name for the "app".
 *
 */
if (!defined('APP_DIR')) {
    define('APP_DIR', 'app');
}
0
votes

Thiago Campezzi's answer works perfectly, I had exact same problem with Kornel

In Config/bootstrap.php, add this line:

Configure::write('App.base','/');

I can't comment or vote yet so I wrote it here :) Thank you!! I search'd hours for this answer!

And by the way, this works with .htaccess and without it, so no need to change this every time you upload new version of app to web server.