303 字 ~ 1 分钟阅读

我们平时开发好一个网站,配置运行地址都是类似:http://localhost/ 或者 http://localhost:2323/ 真难看,前段时间浏览国外技术博客看到一种方法可以个性化定制本地 Web 应用访问地址,例如把 http://localhost:2323/ 改为 http://prj.funnyzak.com/

通过地址栏访问 C:\Windows\System32\drivers\etc\hosts(需管理员权限),用记事本打开(记得备份),格式如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# 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
# 以下都是在2006-2007年恶意修改IE属性,或者传播病毒或者木马的网站
127.0.0.1 localhost
127.0.0.1 858656.com

在最后一行添加如:127.0.0.1 prj.funnyzak.com

保存后本地访问:http://prj.funnyzak.com/ 即可访问本地网站(等同于 http://127.0.0.1/)。