cakephp inside a subdirectory

2019-03-05 02:03发布

I have a problem with cakephp, I can't find a way to get cakephp working in a subdirectory. I have a webpage that resides at www.example.com and I want to have cakephp application on www.example.com/cake. www.example.com is a virtual host and cake is it's subdirectory where all of the cake files and directories are stored. The problem is that when I go to www.example.com/cake it requests a CakeController and has no stylesheets loaded. When I go to www.example.com/cake/users/register (= UsersController::register() ) it shows the right site but again without CSS.

So I need two things...to get www.example.com/cake to display the home page and to get the stylesheets loadedd.

Don't you know how to achieve that?

Thanks in advance

3条回答
迷人小祖宗
2楼-- · 2019-03-05 02:39

Did you read this page in the book and make the appropriate changes in /app/webroot/index.php?

Edit:

The problem is that when I go to www.example.com/cake it requests a CakeController and has no stylesheets loaded.

This seems to indicate that you have the wrong .htaccess in your site's root (www, htdocs ,public_html or whatever) as it's trying to process the request into the CakePHP structure.

It should not look like this

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

Why don't you make life easy for yourself and put CakePHP in the root and move the page(s) that reside at www.example.com into app/webroot. That way it'll behave exactly as you want, i.e:

www.example.com/staticPage.html - displays the static page.

www.example.com/users - displays the users index

Files in webroot are served exactly as if they were in the site's root. Think of the css and javascript files.

查看更多
【Aperson】
3楼-- · 2019-03-05 02:41

I'm not familiar with Cake, but it is almost certainly some sort of path issue. Verify that the path to your stylesheets is accurate.

I know that some frameworks will use a base_url() function(or something similarly named) that returns a config value, you should check your config to ensure that the base URL is set properly.

查看更多
【Aperson】
4楼-- · 2019-03-05 02:42

Most likely your mod_rewrite is not enable in Apache on your hosting account. Check with your host. Another possible problem described below:

Did you change the paths in webroot/index.php?

You need to adjust the paths in that file to point to the Cake core files folder based on your hosting providers directory path.

For example,

if (!defined('CAKE_CORE_INCLUDE_PATH')) { 
    define('CAKE_CORE_INCLUDE_PATH', 'home' . DS .'w3dev' . DS . 'public_html' . DS . 'clients' . DS . 'folderName' . DS . 'remote' . DS . 'v1.1' . DS .  'cake'); 
}

And

if (!defined('APP_DIR')) {
    define('APP_DIR', basename(dirname(dirname(__FILE__))). DS . 'v1.1' . DS . 'app'); 
}

The above all depends on your directory on your hosting server account. As your host for your root path data, so you can point it accordingly.

查看更多
登录 后发表回答