If you want a simple and ready solution for quick testing, go straight to the end of the question
Do not fit door specifications on hosts
, and there is no functionality related to redirects or anything more complex than a pair of Ips x Names.
The hosts
is just an "index", simply you provide a name and it returns an IP, no more, no less. The doors anyway will have to be typed in the browser when accessing the resource, if different from the standard.
The biggest advantage of you creating multiple local domains to point to the 127.0.0.1
in IPV4 it is precisely to be able to test several independent addresses without needing doors or paths different from the real path of the hosted application.
Configuring:
The HOSTS file on Windows 7 and larger is on
C:\Windows\System32\drivers\etc\hosts
In Linux distros it is common for them to be in
/etc/hosts
The syntax of HOSTS is this:
127.0.0.1 localhost
127.0.0.1 webtest.local
127.0.0.1 outroteste.local
You can group by subjects if you prefer to organize:
127.0.0.1 localhost
127.0.0.1 webtest.local outroteste.local maisumteste.local
The port you specify on the web server and when accessing the address. If you want to access without putting port, you need to set the server to port 80, which is the default when omitted to HTTP, and 443 when omitted to HTTPS
If you want port redirection, you need a server answering at port 80 local, to check the names and redirect properly with some script your, but if it is to do this, it pays to simply point out the Virtual Hosts from the server each to the right directory of the sites.
Related:
Configure domain names for the same site (different files) IIS WS2012
Configuring Virtual Hosts in Apache
CORS
One advantage of doing this is that in addition to everything you have control over CORS as you would with any conventional domain, which is not guaranteed using localhost
, depending on the browser.
To learn more about CORS:
What is the meaning of CORS?
Quick solution using third-party service
If you want control over what you’re doing, you need the steps mentioned above, but if you just want to do a quick test on the local machine, someone has kindly set up a DNS service on lvh.me
which always points to the local machine.
So without setting anything up, you can already quit using this address:
http://lvh.me/
that it already points to the local address.
And you can test more than one domains smoothly:
http://jamestk.lvh.me/
http://stackoverflow.lvh.me/
http://qualquercoisa.lvh.me/
Just do not recommend for more definitive things, because it may be that one day the address stops working.
Also, on HOSTS you can point not only to 127.0.0.1
, can point to a local network IP and configure multiple network hosts to the same address, which is not possible in this case here.
To specify Ips, a good alternative is xip.io
. Instead of you using the base address, you include the IP you want as part of the address:
http://nomequeeuquiser.10.0.0.1.xip.io
or simply
http://10.0.0.1.xip.io
which, as you can imagine, will resolve to the address 10.0.0.1
. To use any other address, simply adjust the URL as you wish.
The respsota is the same as @Bacco, I would like to give more details?
– Guilherme Nascimento