Recently encountered a project requires the use of two domain names to facilitate SEO, because of the use of the CodeIgniter framework, although this framework provides a flexible routing function, but can not achieve level two domain name. After much information has been queried, the solution has been obtained after several tests. This example uses www.mysite.com this bogus domain name.
Step 1:
first, establish VirtualHost in httpd.conf
<virtualhost *:80>
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
</VirtualHost>
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 normal access to this domain, the Hosts file must be modified
127.0.0.1 www.mysite.com
127.0.0.1 category.mysite.com
Step 3:
Modification: The _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 out 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 the for 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;
}
}
This is mainly to allow URLs to be correctly understood by CI.
Step 4: Create a domain.php file under application/config/ . The contents are as follows:
<?php
if (! defined (' BasePath '))
exit (' No Direct script access allowed ');
$domain = Array (' category ', "detail", "info", "archive");
This is basically done, but when using Site_url (), if you want to use the level two domain name, you have to do another processing.