How to change localhost/site to site.dev

2020-08-01 08:12发布

问题:

I use XAMPP for local development and I've heard of developers that change the url structure from localhost/site to site.dev, but I'm not sure how to go about it.

How can I change it and is there anything I should know before changing it?

回答1:

You'll need to add an entry in your host file to map site.dev to localhost

127.0.0.1 site.dev www.site.dev

and add a virtual host in apache to detect it

<VirtualHost *:80>
    DocumentRoot /path/to/document/root/site/
    ServerName site.dev
    ServerAlias  www.site.dev
# Other directives here
</VirtualHost>

<VirtualHost *:80>
    DocumentRoot /path/to/document/root/
    ServerName localhost
# Other directives here
</VirtualHost>


回答2:

You can point site.dev to 127.0.0.1 in your hosts file and create a binding for the url in the apache config file so that requests from that url point at a specific site/folder in xampp. I've done this in the past for development projects and generally works pretty well.



标签: xampp