1

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?

wbcmac2000
  • 15
  • 1
  • 6
  • Windows or linux? You can use simpledns.com for Windows. – ramazan polat Nov 01 '14 at 20:26
  • possible duplicate of [How do I redirect a domain to another domain locally?](http://superuser.com/questions/601574/how-do-i-redirect-a-domain-to-another-domain-locally), also see: [Can't map certain port and path with hosts file](http://superuser.com/questions/344870/cant-map-certain-port-and-path-with-hosts-file), http://superuser.com/questions/732135/editing-etc-hosts-to-use-domain-name-instead-of-ip-address, http://superuser.com/questions/97213/redirect-one-domain-to-other-using-hosts-file-or-similar, – Ƭᴇcʜιᴇ007 Nov 01 '14 at 20:42
  • How can I do it without a program or DNS? – wbcmac2000 Nov 01 '14 at 20:59
  • Do you want to redirect requests or map one domain's IP to another one? `hosts` file doesn't redirect anything, it overrides DNS lookups (so domains are resolved to IPs from `hosts`). So do you want to redirect requests pointed at a domain, or resolve that domain's IP to another domain's IP? – gronostaj Nov 01 '14 at 21:44
  • map one domain to another IP – wbcmac2000 Nov 01 '14 at 23:08
  • Then `nslookup` that second domain and use its IP in `hosts` file. – gronostaj Nov 02 '14 at 17:03

1 Answers1

12

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