Loading

Apache配置一级域名、二级域名、子域名

关于域名介绍:

一般来说,一个完整的域名用二个或者二个以上部分组成,各部分之间用英文的句号“.”开分割。如“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可以称为“子域名”;

二级域名和子域名的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.)或者子域名),

在ThinkPHP工程中,通过这里配置不同入口文件index.php 、mobile.php可以便捷区分不同的模块入口,结合.htaccess文件最终达到可以简化路由url的目的。

如果httpd-vhost.conf文件配置不起作用,要注意两点:

1、Apache配置文件httpd.conf中允许加载http-vhosts.conf模块:

# Virtual hosts
Include conf/extra/httpd-vhosts.conf

2、开启rewrite-module功能;

 

测试环境下,可以配置系统host文件,添加

192.168.1.122 testimmi.com
192.168.1.122 m.testimmi.com
192.168.1.122 www.testimmi.com

来模拟申请到二级域名的情况

 

posted @ 2016-09-22 11:55  集君  阅读(15696)  评论(0编辑  收藏  举报