It is best to close xampp before setting
1. Modify the Hosts file
Go to the C:\WINDOWS\SYSTEM32\DRIVERS\ETC directory and locate the hosts file.
In
# Localhost (do not REMOVE) Start
127.0.0.1localhost
The back
Add your URLs
Like 127.0.0.1 www.myweb.com #你的网址
This way, when you visit www.myweb.com, you will jump directly to 127.0.0.1 (local) instead of the real www.myweb.com site.
If it is a non-80 port, no other changes are required because the browser only has 80 ports, which means that the port number must be added when visiting the site. Like www.myweb.com:80.
2. Open httpd.conf File
Under the Config button in the XAMPP Control Panel, click Apache (http.conf) to enter. Or you can use the directory
Directory to install XAMPP: \xampp\apache\conf\http.conf Modify
(1) Find httpd-vhosts.conf
If there is a semicolon in front of it, remove it, this ensures that the virtual host is turned on.
(2) Find allowoverride all
Found it
<directory "C:/xampp/cgi-bin" >
AllowOverride All
Options None
Require all granted
</Directory>
Replaced by
<directory "C:/xampp/cgi-bin" >
Options Indexes FollowSymLinks includes execcgi
AllowOverride All
Order Allow,deny
Allow from all
</Directory>
(3) Find "DocumentRoot" and modify the path.
Found it:
DocumentRoot "C:/xampp/htdocs"
To be replaced by:
DocumentRoot "c:/xampp/htdocs/the folder where your project is located"
3. Modify the Http-vhosts.conf file
Find http-vhost.conf file in C:\xampp\apache\conf\extra
(1) Find # #NameVirtualHost *:80 Remove the previous pound note
(2) Add the following code
<virtualhost *:80> #如果是非80端口, change the port number that you are currently using
DocumentRoot "C:/xampp/htdocs/myproject" #此处为要访问的文件夹
ServerName www.myweb.com #此处为之前在hosts中对应的要访问的网址
</VirtualHost>
<directory "C:/xampp/htdocs/myproject" > #此处请修改为对应的文件夹
Options Indexes FollowSymLinks includes execcgi
AllowOverride All
Order Allow,deny
Allow from all
</Directory>
<virtualhost *:80> #此段为默认访问设置 To ensure that you can still access using localhost
DocumentRoot "C:/xampp/htdocs/myproject" #此处请修改为项目所在的文件夹
ServerName localhost
</VirtualHost>
4. Restart XAMPP
5. Open the browser, enter www.myweb.com can be accessed, not 80 port, add port number, such as 8080 Port www.myweb.com:8080
Also enter localhost will open the project, not 80 port still to be in the form of localhost: port number to access
Configuring the XAMPP virtual host on Windows7