Method of binding secondary domain name by YII module

  • 2021-07-07 06:44:11
  • OfStack

The YII module mainly has the following steps to bind level 2 domain names:

First set in the configuration file:


'urlManager' => array(
'urlFormat' => 'path',
'showScriptName' => false, // Attention false Don't enclose it in quotation marks 
'urlSuffix' => '.html',
'rules' => array(
'http://test.ofstack.com'=>array('/blog', 'urlSuffix'=> " , 'caseSensitive'=>false),
),

blog is a module. If there is a second controller under blog module (take comment as an example here), one more rule needs to be written, as follows:


'urlManager' => array(
'urlFormat' => 'path',
'showScriptName' => false, // Attention false Don't enclose it in quotation marks 
'urlSuffix' => '.html',
'rules' => array(
'http://test.ofstack.com'=>array('/blog', 'urlSuffix'=> " , 'caseSensitive'=>false),
'http://test.ofstack.com/comment-<id:\w+>'=>array('/blog/comment/', 'urlSuffix'=>'.html', 'caseSensitive'=>false),
),

URL to access a comment under blog would be: http://test.ofstack.com/comment-1. html

The situation of local server:

1. If it is not enough to set in YII configuration, it is necessary to resolve the domain name of test. ofstack. com level 2 to the program server in DNS server, which can be added at the end of hosts


127.0.0.1    www.ofstack.com   test.ofstack.com

2. You also need to add in the http. conf of the apache server:


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

If you need to bind multiple level 2 domain names, you only need to add them repeatedly.


Related articles: