CI Framework multi-Directory settings

Source: Internet
Author: User
Tags codeigniter

1, set purpose, the front and back office to achieve independent directory management

2. Access the foreground through http://www.myci.com, access the backstage through the Http://www.myci.com/admin,

Multi-directory means that there are many sets of programs in the same website, the simplest example is the site's foreground display and background management. Because of the function of the site in different parts, usually have a different interface, with the images/stylesheet/javavascript is basically separate, so set different eyes as follows:

Website Front desk url:http://www.myci.com website backstage Management url::http://www.myci.com/admin
CI 2.0 Source code download after decompression file structure, such as, the default is only one directory

2, set the entry file. Because the root directory of the index.php default is to find the applcation under the controllers controller, in order to read the controller under the applcation/admin/controllers, we need to create a new admin file under the site root directory, and copy the index.php under the root directory here, and then edit this index.php to find:

1 $system_path"system";   //改为 $system_path = "../system";
2 $application_folder="application";  //改为 $application_folder = "../application/admin";

In addition, this directory may be used in the Css/js/images folder can also be placed under the new admin.

After the first goal is completed, now through the URL http:www.//myci/admin can read the current application inside the configuration file in the default settings of the controller welcome, but for the non-default controller read URL is slightly longer, such as in the admin/ Applcation/controllers has a login controller (the corresponding program is the login Class) to display the background landing page, need to pass this URL to access http://www.myci/admin/index.php/login/ Index, according to the CI rule, if the method that does not write the class in the URL reads the index () method by default, the above URL can also be accessed through Http://www.myci/admin/index.php/login.

The goal to achieve is obviously not the above, and this URL has a index.php is looking uncomfortable, the real goal is to remove it. The implementation is very simple, that is, through the. htaccess file to the URL rewrite (rewrite). Next, create a. htaccess file in the admin file in the root directory, with the following content:

Rewriteengine on

Rewritecond $!^ (index\.php|images|css|js|scripts|robots\.txt)

Rewriterule ^ (. *) $/manage/index.php/$1 [L]

—————————————————————————— attached,. Htacess knowledge



Official method: By default,index.php will be included in your URL:

Example.com/index.php/news/article/my_article

You can easily remove it by using the. htaccess file to set some simple rules. The following is an example of using the "negative" method to redirect non-specified content:

Rewriteengine on
Rewritecond $!^ (index\\.php|images|robots\\.txt)
Rewriterule ^ (. *) $/index.php/$1 [L]

Note: If your project is not in the root directory, please change the above sentence to:rewriterule ^ (. *) $ index.php/$1 [L]

In the above example, any HTTP requests that can implement any non-index.php, images, and robots.txt are directed to index.php.


The question of the official approach:

1. No description of the directory to which the. htaccess file was created; the. htaccess file is placed in the index.php directory, typically CodeIgniter and directory.

2. Do not control the. htaccess in the application and system directories.

3. If the project is not in the root directory, you need to add the path of the directory where CI is located in the last sentence, Rewriterule ^ (. *) $/ci_dir/index.php/$1 [L]

eg. index.php file in Wwwroot\\codeigniter,wwwroot is the directory, then the last sentence is changed to Rewriterule ^ (. *) $/codeigniter/index.php/$1 [L]


4. [Intermediate] effectively delete index.php in the URL http://codeigniter.org.cn/forums/thread-15444-1-1.html The Rewritecond!^ (INDEX\\\\.PHP|IMAGES|ROBOTS\\\\.TXTL) In this blog is the last one L

5. Apache typically loads the rewrite module by default and can view the apache\\conf\\httpd.conf file

LoadModule Rewrite_module modules/mod_rewrite.so

The following does not need to be modified

<directory/>
Options FollowSymLinks
allowoverride None
Order Deny,allow
Deny from all
</Directory>


6. You do not need to modify the application/config/config.php in the$config [' index_page '] = ' index.php ';

CI Framework multi-Directory settings

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.