2016-01-12 30 views
0

我有一個子域。我想使用xampp(apache)在本地爲它設置虛擬主機。如何爲子域設置虛擬主機?

例如,我想使用test.mywebsite.com 我想通過打開此子域來運行本地文件。

我已經嘗試了幾乎所有的文章/幫助材料在線設置虛擬主機的子域,但徒勞無功。

我嘗試以下,但沒有工作:

的httpd-vhosts.conf:

<VirtualHost *:80> 
DocumentRoot "E:/xampp/htdocs/project" 
ServerName mywebsite.com 
ServerAlias test.mywebsite.com 

hosts文件:

127.0.0.1 mywebsite.com 
127.0.0.1 test.mywebsite.com 

我會感激的任何建議/幫幫我。 謝謝

+0

是的,我使用的是Windows 10 –

+0

那你試試?你目前的httpd.conf文件是什麼?和主機文件? –

+0

所以你要求子域名?那麼子域名基本上只是你當前目錄中的一個文件夾。例如:test.localhost.dev。你不能使用任何官方域名。如.com,.org,.net,.gov等。 – RepeaterCreeper

回答

0

編輯C:\xampp\apache\conf\extra\httpd-vhosts.conf並添加以下行。確保將dir替換爲原始文檔根目錄。

<VirtualHost *:80> 
    ServerName test.mywebsite.com 
    DocumentRoot "C:\xampp\htdocs\dir" 
    <Directory "C:\xampp\htdocs\dir"> 
     DirectoryIndex index.php 
     AllowOverride All 
     Order allow,deny 
     Allow from all 
    </Directory> 
</VirtualHost> 

重啓apache然後編輯C:\Windows\System32\Drivers\etc\hosts,並在底部添加以下行。

127.0.0.1 test.mywebsite.com

+0

感謝您的回覆。我在上面嘗試過,但它仍然沒有工作。它只有在我禁用我的互聯網時纔有效。否則,它只拾取現場版本。 –