標籤:
關於網域名稱介紹:
一般來說,一個完整的網域名稱用二個或者二個以上部分組成,各部分之間用英文的句號“.”開分割。如“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
來類比申請到次層網域的情況
網站部署頂層網域、次層網域、子網域名稱