CodeIgniter中實(shí)現(xiàn)泛域名解析
最近遇到一個(gè)項(xiàng)目要求使用二級(jí)域名,以方便SEO,由于采用的是CodeIgniter框架,這個(gè)框架雖然提供了靈活的路由功能,但是不能實(shí)現(xiàn)二級(jí)域名。查詢了多很資料之后,經(jīng)過(guò)幾番測(cè)試得出了解決方法。本例采用www.mysite.com這個(gè)假域名。
步驟1:
首先在httpd.conf中建立virtualhost
<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>
步驟2:
我要實(shí)現(xiàn)這樣的效果:
http://www.mysite.com/category/news/1.html =====> http://category.mysite.com/news/1.html
為了確保能正常訪問(wèn)這個(gè)domain,必須修改hosts文件
127.0.0.1 www.mysite.com 127.0.0.1 category.mysite.com
步驟3:
修改:system/core/URI.php的_set_uri_string方法
/** * 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 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; } }
這里主要是為了讓URL能正確的被CI理解。
步驟4:在application/config/下建立一個(gè)domain.php文件。內(nèi)容如下:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); $domain = array('category',"detail","info","archive");
至此已經(jīng)基本完成了,不過(guò),使用site_url()的時(shí)候,如果要使用二級(jí)域名,就得另做處理了。
- apache+codeigniter 通過(guò).htcaccess做動(dòng)態(tài)二級(jí)域名解析
- 解析CodeIgniter自定義配置文件
- 解析CI即CodeIgniter框架在Nginx下的重寫(xiě)規(guī)則
- CodeIgniter中使用cookie的三種方式詳解
- CodeIgniter模板引擎使用實(shí)例
- CodeIgniter實(shí)現(xiàn)更改view文件夾路徑的方法
- CodeIgniter框架過(guò)濾HTML危險(xiǎn)代碼
- 讓CodeIgniter的ellipsize()支持中文截?cái)嗟姆椒?/a>
- 新浪SAE云平臺(tái)下使用codeigniter的數(shù)據(jù)庫(kù)配置
- codeigniter集成ucenter1.6雙向通信的解決辦法
- 使用CodeIgniter的類庫(kù)做圖片上傳
相關(guān)文章
ThinkPHP模板判斷輸出Defined標(biāo)簽用法詳解
這篇文章主要介紹了ThinkPHP模板判斷輸出Defined標(biāo)簽用法詳解,需要的朋友可以參考下2014-06-06ThinkPHP3.1.2 使用cli命令行模式運(yùn)行的方法
這篇文章主要介紹了ThinkPHP3.1.2 使用cli命令行模式運(yùn)行的方法,本文給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2020-04-04ThinkPHP 6 添加跳轉(zhuǎn)提示擴(kuò)展 liliuwei/thinkphp-jump的操作
liliuwei/thinkphp-jump 是 TP5 中經(jīng)典跳轉(zhuǎn)提示,在 TP6 中已經(jīng)取消,通過(guò) composer 下載該擴(kuò)展可以在 TP6 中使用 TP5 的跳轉(zhuǎn)提示操作,這篇文章主要介紹了ThinkPHP 6 添加跳轉(zhuǎn)提示擴(kuò)展 liliuwei/thinkphp-jump,需要的朋友可以參考下2023-08-08Zend Framework緩存Cache用法簡(jiǎn)單實(shí)例
這篇文章主要介紹了Zend Framework緩存Cache用法,以簡(jiǎn)單實(shí)例形式分析了Zend Framework使用緩存的具體步驟,配置文件與Cache緩存具體使用技巧,需要的朋友可以參考下2016-03-03以PHP代碼為實(shí)例詳解RabbitMQ消息隊(duì)列中間件的6種模式
這篇文章主要介紹了以PHP代碼為實(shí)例詳解RabbitMQ消息隊(duì)列中間件的6種模式,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2023-05-05PHP yii實(shí)現(xiàn)model添加默認(rèn)值的方法(兩種方法)
這篇文章主要介紹了PHP yii實(shí)現(xiàn)model添加默認(rèn)值的方法的相關(guān)資料,這里有兩種方法,和具體實(shí)現(xiàn)方法,需要的朋友可以參考下2016-11-11