Implement pan domain name resolution in CodeIgniter _php

Source: Internet
Author: User
Keywords CodeIgniter pan domain parsing
Tags codeigniter
CI Framework

Recently encountered a project requires the use of level two domain name, to facilitate SEO, due to the use of the CodeIgniter framework, although the framework provides flexible routing capabilities, but can not achieve level two domain names. After a lot of data has been queried, several tests have come to a solution. This example uses www.mysite.com this fake domain name.

Step 1:

First, establish VirtualHost in httpd.conf

 
  
   
    ServerAdmin admin@163.com  documentroot "D:/www/cms"  ServerName www.mysite.com serveralias *.mysite.com  #这里采用泛解析的方式  errorlog "Logs/mysite.com-error.log"  customlog "Logs/mysite.com.log" common
 
  

Step 2:

I want to achieve this effect:
http://www.mysite.com/category/news/1.html =====> http://category.mysite.com/news/1.html
In order to ensure proper access to this domain, the Hosts file must be modified

127.0.0.1 www.mysite.com127.0.0.1 category.mysite.com

Step 3:

Modification: _set_uri_string method of system/core/uri.php

/** * Set The URI String * * @access public * @param String * @return string */function _set_uri_string ($STR) {//Filter O UT control characters $str = Remove_invisible_characters ($str, FALSE); If The URI contains only a slash we'll kill it $this->uri_string = ($str = = '/')? ": $str; Add by Fengyun to URL rewrite at 2013-1-25 1:02:27 @include (APPPATH. ' Config/domain '. EXT); $arrServerName = Explode ('. ', $_server[' server_name '); if (In_array ($arrServerName [0], $domain)) {$this->uri_string = '/'. $arrServerName [0]. " /" . $this->uri_string; }}

The main purpose here is to allow the URL to be correctly understood by CI.

Step 4: Create a domain.php file under application/config/ . The contents are as follows:

<?PHPIF (! defined (' BasePath ')) exit (' No Direct script access allowed '), $domain = Array (' category ', "detail", "info", " Archive ");

This has basically been done, however, when using Site_url (), if you want to use a level two domain name, you have to do something else.

  • 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.