看慣了http://localhost在本地測試的網域名稱,想換種寫法行不行,比如說想變成http://www.111cn.net,但網頁訪問仍然是原來http://localhost的內容,如何做到呢?
可以修改原生一個檔案來實現。
在系統硬碟中的如下路徑
代碼如下 |
複製代碼 |
C:WINDOWSsystem32driversetc |
找到“hosts”檔案,右鍵開啟檔案選擇文字檔方式,可以看到如下內容:
代碼如下 |
複製代碼 |
# Copyright (c) 1993-1999 Microsoft Corp. # # This is a sample HOSTS file used by Microsoft TCP/IP for Windows. # # This file contains the mappings of IP addresses to host names. Each # entry should be kept on an individual line. The IP address should # be placed in the first column followed by the corresponding host name. # The IP address and the host name should be separated by at least one # space. # # Additionally, comments (such as these) may be inserted on individual # lines or following the machine name denoted by a '#' symbol. # # For example: # # 102.54.94.97 rhino.acme.com # source server # 38.25.63.10 x.acme.com # x client host |
127.0.0.1 localhost
看到了吧,在最下邊一行有
127.0.0.1 localhost
大家知道怎麼做了吧?
就是在這行下添加新行,將localhost修改為想要的網域名稱,如下
127.0.0.1 www.111cn.net
需要注意的是,“127.0.0.1”和“www.111cn.net”之間用Tab鍵間隔開
想添加什麼網域名稱就接著往下加好了,就這麼簡單。
添加完成後就儲存,然後就可以用www.111cn.net訪問自己本地的網站了。