_php instance of CodeIgniter in the implementation of universal domain name resolution

Source: Internet
Author: User
Tags control characters codeigniter

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.

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.