Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Editing hosts file to redirect url? [closed]

Tags:

windows

hosts

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

like image 949
Glory Avatar asked Jul 16 '10 15:07

Glory


People also ask

How do I redirect a URL in host file?

Inserting a redirect into the hosts file is simple. Just enter the IP address of the desired server or host, leave a single space, and then enter the domain or hostname you want to point to that IP. Enter only one redirect per line.

What happens if I edit my hosts file?

Modifying your hosts file causes your local machine to look directly at the Internet Protocol (IP) address that you specify. Rackspace offers managed hosting solutions to assist with the handling of these resources.

How do I unblock a website from my hosts file?

To Unblock Websites Blocked in the Hosts File, Navigate to the folder C:\Windows\System32\drivers\etc. Select "All Files" from the drop-down menu. Double-click the hosts file. Add the comment symbol # at the beginning of the line that contains the blocked web site you want to unblock.


2 Answers

No, but you could open a web server at, for example, 127.0.0.77 and use it to check if the Request URI is "/welcome.aspx"... If yes redirect to google, if not load the original site.

127.0.0.77      mysite.com 
like image 132
Raphael R. Avatar answered Sep 21 '22 18:09

Raphael R.


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.

like image 40
David Avatar answered Sep 23 '22 18:09

David