请教qiang和各位前辈关于2级域名绑定到module的做法?

有个项目中遇到这样的需求。

我们使用了yii提供的module结构。把系统划分为newssite,member,admin几个module。

按照默认的www.example.com/member,www.example.com/admin都能正常访问各module

现在希望能通过admin.example.com,member.example来访问各自的module,不知道该怎么做。

在论坛里找了一篇用urlmanager做的,说用Parameterizing Hostnames来做,设置了一下没有成功。通过2级域名访问的时候,跑到vhost上设置的default站点上去了。

希望能讲一下详细的步骤,谢谢!

555,没人理啊,不知道是不是要先做*.example.com的泛解析呢。

个人意见,可能不对。

1、需要到域名托管商处设置二级域名绑定,

就是在原先你添加www.exmple.com的设置处,设置admin.exmple.com等二级绑定;

2、本地服务器设置

在入口index.php中,设置映射

做一个循环,处理,类似如下:

以下代码是asp代码,需要修改为php代码。

<%

requireURL = request.ServerVariables("HTTP_HOST")

Select Case requireURL

Case &quot;admin.example.com&quot; response.redirect &quot;admin/index.php&quot;


Case &quot;aaa.example.com&quot; response.redirect &quot;aaa/index.php&quot;&quot;


Case Else response.redirect &quot;site/index.html&quot;	

End Select

%>

如果你修改可以了,不妨共享一下代码。

应该有更好的方法,希望其他专业人士帮助。

二级域名与ip绑定一定是少不了的。

我虽然没有尝试过,但你试一下——使用rewrite方式进行绑定。

思路就是将

/admin/ 开头的 全部指向到 index.php?r=admin 去。我省略写了url后面部分,具体参考rewrite手册。

看手册




'urlManager'=>array(

				'urlFormat'=>'path',

				'showScriptName' => false,

				'urlSuffix' => '.html',

				'rules'=>array(				

					//图片

					'http://www.app.com/imagescache/<date>/<id:\d+>-<size:[a-zA-Z0-9]*>.<ext:jpg|gif|jpeg>'=>array('attachment/view', 'urlSuffix'=>false,'caseSensitive'=>false),

					

					//新闻

	                'http://news.app.com/'=>array('news/index','urlSuffix'=>false),

	                'http://news.app.com/<_a>'=>array('news/<_a>'),

					

	                //博客

	                'http://blog.app.com/<u:\d+>'=>array('blog/broker/index','urlSuffix'=>false),

	                'http://blog.app.com/<u:\d+>-<_a>'=>array('blog/broker/<_a>'),	

	                //首页

	                'http://www.app.com/'=>array('site/index','urlSuffix'=>false),

	                //用户后台

	                'http://www.app.com/account/'=>array('account/default/index'),

	                'http://www.app.com/account/<_c>/<_a>'=>array('account/<_c>/<_a>'),

	                //超级管理员

	                'http://www.app.com/admin/'=>array('admin/default/index'),

	                'http://www.app.com/admin/<_c>/<_a>'=>array('admin/<_c>/<_a>'),

	                //前台

	                'http://www.app.com/<controller:\w+>/<action:\w+>'=>'<controller>/<action>',

				),

			),



仅作参考,当然前提是要把上面几个二级域名或者*都指到你的应用下