Editing hosts file to redirect url?

Glory picture Glory · Jul 16, 2010 · Viewed 105.4k times · Source

I know you can edit a hosts file to redirect a URL to an IP address as so:

127.0.0.1 google.com

but how do you force a redirect to a URL instead of an IP address?

e.g.

mysite.com/welcome.aspx google.com

The explicit URL doesn't work and assuming mysite.com's IP is 222.222.222.222, the following doesn't work either:

222.222.222.222/welcome.aspx google.com

Answer

David picture David · Jul 16, 2010

You can't. A redirect requires a webserver to accept the first request and send back the redirect. The "hosts" file just lets you set your own DNS records.