关于域名介绍:php
通常来讲,一个完整的域名用二个或者二个以上部分组成,各部分之间用英文的句号“.”开分割。如“www.baidu.com”,其中最后一个“.”的右边部分“.com”成为顶级域名(TLD,也成为一级域名,相似还有.cn,.net,.org,.gov,.edu,.tv等等,这里.com.cn实际上是.cn下的二级域名)。任何我的均可以注册一个.com域名,其中baidu.com也就是顶级域名.com下的二级域名,baidu.com还能够有image.baidu.com、music.baidu.com的形式,这里的image\music能够称为“子域名”;html
二级域名和子域名的Apache配置:测试
进入Apache-conf-extra-httpd-vhost.conf,添加以下配置:网站
<VirtualHost *:80> DocumentRoot "E:/wamp/www/galaxyPHP/" ServerName testimmi.com ServerAlias m.testimmi.com <Directory "E:/wamp/www/galaxyPHP/"> Allow from all </Directory> <IfModule dir_module> DirectoryIndex mobile.php index.html index.htm default.php default.htm default.html </IfModule> </VirtualHost> <VirtualHost *:80> DocumentRoot "E:/wamp/www/galaxyPHP/" ServerName testimmi.com ServerAlias www.testimmi.com <Directory "E:/wamp/www/galaxyPHP/"> Allow from all </Directory> <IfModule dir_module> DirectoryIndex index.php index.html index.htm default.php default.htm default.html </IfModule> </VirtualHost>
其中DocumentRoot就表明网站工程所在目录,ServerName表明二级域名,ServerAlias就是别名(容许是完整二级域名(带www.)或者子域名),url
在ThinkPHP工程中,经过这里配置不一样入口文件index.php 、mobile.php能够便捷区分不一样的模块入口,结合.htaccess文件最终达到能够简化路由url的目的。spa
若是httpd-vhost.conf文件配置不起做用,要注意两点:.net
一、Apache配置文件httpd.conf中容许加载http-vhosts.conf模块:code
# Virtual hosts
Include conf/extra/httpd-vhosts.confhtm
二、开启rewrite-module功能;blog
测试环境下,能够配置系统host文件,添加
192.168.1.122 testimmi.com
192.168.1.122 m.testimmi.com
192.168.1.122 www.testimmi.com
来模拟申请到二级域名的状况