In the hosts file how do I make it instead of redirecting to an IP address redirect to either a domain(example.com) or a URL on an IP address(127.0.0.1/example.html)? I tried typing it in but it doesn't work. I need to know how for Windows and Linux. How can I do it without a program or DNS?
1 Answer
The hosts file is called hosts for a reason, it is about exactly that, hosts. You can redirect a hostname to a different IP, but not a specific location at that ip. What you are trying to do is not supported, because you aren't directing a host to an IP, you are directing to an address.
Single Hostname:
1.2.3.4.5.6 example.com # redirects example to example ip
Double Hostnames:
1.2.3.4.5.6 example.com example.net # redirects examples to example ip
-
+1, great first answer. I don't see many new users start off this well.– bwDracoNov 3, 2014 at 2:20
hosts
file doesn't redirect anything, it overrides DNS lookups (so domains are resolved to IPs fromhosts
). So do you want to redirect requests pointed at a domain, or resolve that domain's IP to another domain's IP?