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.