Heim  >  Artikel  >  Backend-Entwicklung  >  YII模块实现绑定二级域名的方法_PHP

YII模块实现绑定二级域名的方法_PHP

WBOY
WBOYOriginal
2016-06-01 11:51:58867Durchsuche

YII模块实现绑定二级域名主要有如下步骤:

首先在配置文件设置:

'urlManager' => array(
'urlFormat' => 'path',
'showScriptName' => false, //注意false不要用引号括上
'urlSuffix' => '.html',
'rules' => array(
'http://test.bitsCN.com'=>array('/blog', 'urlSuffix'=>”, 'caseSensitive'=>false),
),

blog 为一个模块 ,如果在blog模块下还存在第二个控制器(这里以comment为例),则需要多写一个规则,如下:

'urlManager' => array(
'urlFormat' => 'path',
'showScriptName' => false, //注意false不要用引号括上
'urlSuffix' => '.html',
'rules' => array(
'http://test.bitsCN.com'=>array('/blog', 'urlSuffix'=>”, 'caseSensitive'=>false),
'http://test.bitsCN.com/comment-<id:\w+>'=>array('/blog/comment/', 'urlSuffix'=>'.html', 'caseSensitive'=>false),
),

如要访问blog下的某一条评论的URL会是:http://test.bitsCN.com/comment-1.html

本在地服务器的情况:

一、在YII配置中设置了还不够的,还需要在DNS服务器中把test.bitsCN.com二级域名解析到程序服务器,可以在hosts中的最后加入

127.0.0.1    www.bitsCN.com   test.bitsCN.com

二、还需要在apache服务器的http.conf中添加:

NameVirtualHost *:80
<VirtualHost *:80>
ServerAdmin kane@bitsCN.com
DocumentRoot E:/wamp/www/k1029
ServerName test.bitsCN.com
ErrorLog logs/test.bitsCN.com-error_log
CustomLog logs/test.bitsCN.com-access_log common
</VirtualHost>

如果需要绑定多个二级域名,则只要重复添加即可.

Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn