本文主要和大家分享phpstydy本地配置域名訪問的方法,希望能幫助到大家。
一. hosts配置:
1.用編輯器打開hosts文件,位置:C:\Windows\System32\drivers\etc目錄下
示例:
在hosts文件的最后添加如下代碼:
127.0.0.1 www.tp5.com |

2. 進入開啟的虛擬主機文件httpd-vhosts.conf進行域名配置,位置:\phpStudy\Apache\conf\extra目錄下
配置規(guī)則:
<VirtualHost *:80> ServerAdminwebmaster@dummy-host.example.com DocumentRoot"D:/phpStudy/WWW/要配置域名的項目名" ServerName 配置的域名 ErrorLog"logs/dummy-host2.example.com-error.log" CustomLog"logs/dummy-host2.example.com-access.log" common </VirtualHost> |
若想在Apache的配置中隱藏入口文件index.php,即使訪問地址:localhost/h5.test.cn/index.php/test/index 簡化成 localhost/h5.test.cn/test/index,也可以通過域名配置實現(xiàn),即如下:
<VirtualHost *:80> DocumentRoot"D:/phpStudy/WWW/h5.test.cn" ServerNamelocal.h5.test.cn <IfModuledir_module> DirectoryIndexindex.php </IfModule> </VirtualHost> |
以上配置都完成后,切記要重啟服務(wù)器。
注意:這個時候出現(xiàn)一個問題,就是用localhost訪問本地其他項目就出現(xiàn)訪問不了,這么多項目,不想每個都去配置一個虛擬域名,既能域名訪問,又能localhost就好了,在網(wǎng)上找到了解決辦法:
用上面的方法添加一個名為localhost的域名綁定到www目錄,然后在httpd.conf文件中注釋掉ServerName localhost這一行,重啟apache,就都可以訪問了。