Before I start, please note that there are five places, which have both the files .htaccess and index.php. In the default structure of CakePHP package, they are /, /app, /app/webroot, and another two places (they are folders under the sub folder of /cake but they are not related to this topic. In folders / and /app, the files .htaccess and index.php have the same function, redirecting the requests to the folder webroot. The difference is that file .htaccess is for the case applying mod rewrite and the file index.php is for the case not applying mod rewrite. However, they are not useful for advanced setup. We will only concern the two files, .htaccess and index.php, under /app/webroot and every time mentioned below refer to them.
Suppose in your web hosting account you have two domains, site_a.com and site_b.net, which are developed using CakePHP and you want them to share the same CakePHP library functions. The directory structure may be like as the followings,
- /.../www/ is the root directory of your account,
- /.../www/site_a.com/ is the document root of domain site_a.com, and
- /.../www/site_b.net/ is the document root of domain site_b.net.
- /.../www/cakephp_lib/ is the folder where place CakePHP library functions under cake,
- /.../www/site_a_app/ is to place the files under app for site_a.com, and
- /.../www/site_b_app/ is to place the files under app for site_b.net.
- upload all folders and files under cake_1.2/app/webroot/ to site_a.com/ and site_b.net/, respectively, (here I omit /.../www/ for easy reading)
- remove the folder cake_1.2/app/webroot and its files and sub folders,
- upload the whole folder cake_1.2/app/ to site_a_app/ and site_b_app/, respectively,
- remove the folder cake_1.2/app and its files and sub folders,
- upload all folders and files left in the folder cake_1.2/ to cakephp_lib/, and
- remove the folder cake_1.2 for clean up.
- ROOT: the path of the root directory of the application files,
- APP_DIR: the directory name which includes the application files under the ROOT directory, and
- CAKE_CORE_INCLUDE_PATH: the path of the directory that includes the cake libraries.
- ROOT: /.../www/site_a_app,
- APP_DIR: app, and
- CAKE_CORE_INCLUDE_PATH: /.../www/cakephp_lib.
- ROOT: /.../www/site_b_app,
- APP_DIR: app, and
- CAKE_CORE_INCLUDE_PATH: /.../www/cakephp_lib.
The code for site_a.com after removing all comments is as the following (suppose the document root is /101010/www/),
define('ADVANCED_CAKE_DOCUMENT_ROOT', DS.'101010'.DS.'www');
if (!defined('ROOT')) {
define('ROOT', ADVANCED_CAKE_DOCUMENT_ROOT.DS.'site_a_app');
}
if (!defined('APP_DIR')) {
define('APP_DIR', 'app');
}
if (!defined('CAKE_CORE_INCLUDE_PATH')) {
define('CAKE_CORE_INCLUDE_PATH',
ADVANCED_CAKE_DOCUMENT_ROOT.DS.'cakephp_lib');
}
If you still get an error with a message like "The requested URL /.../www.site_a.com/index.php was not found on this server.", you may add
RewriteBase /
to the file .htaccess.
No comments:
Post a Comment