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