When developing web programs, we sometimes do this, which is to modify the hosts file to do virtual domain name mapping to facilitate local development. For example, point the domain name www.phpernote.com to the local 127.0.0.1. This operation process itself is not complicated at all, but in the Windows environment, the hosts file is hidden very deep, so every time we have to Baidu the hosts file path and then open the file directory layer by layer to find the file. If you change it frequently, it will be really troublesome, so here I have summarized a relatively good and slightly masterful method to share.
(1) Use text editing software such as Notepad to write the following code:
::去除hosts文件只读属性 attrib -R C:\windows\system32\drivers\etc\hosts ::用notepad编辑hosts文件 notepad C:\windows\system32\drivers\etc\hosts ::给hosts文件加上只读属性 attrib +R C:\windows\system32\drivers\etc\hosts
Then save the file as a .bat file with a suffix name (for example: hosts.bat).
(2) Place the file into the WINDOWSsystem32 directory. In fact, it does not have to be placed in this directory. You can create a new directory anywhere and copy the full path of the directory. Just go to the environment variables of the Windows system.
OK, two simple steps. If you need to modify the hosts file in the future, just enter hosts directly during operation. After pressing Enter, the system will automatically make the hosts file writable, then open the hosts file and wait for the editing to be completed. When exiting, the file will automatically become read-only.