關於域名介紹: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
來模擬申請到二級域名的狀況