Tutorial :Editing hosts file to redirect url?


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

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


mysite.com/welcome.aspx google.com

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


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.


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


Apply this trick.

First you need IP address of url you want to redirect to. Lets say you want to redirect to stackoverflow.com To find it, use the ping command in a Command Prompt. Type in:

ping stackoverflow.com  

into the command prompt window and you’ll see stackoverflow's numerical IP address. Now use that IP into your host file google.com

yay now google is serving stackoverflow :)


hosts file: google.com - ip of your server.

Run script on the server for redirecting users to url that you want.


You could use the RedirectMatch directive in Apache to do something similar you want.

It's pretty simple.

RedirectMatch /

Anyway, I can't see any reason to do that thing. Aren't you trying to intercept traffic? There are better ways. For Linux boxes as a router: iptables -j REDIRECT + Squid or Apache. For Cisco routers, you can use WCCP to a Cache or Web Server...

Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Next Post »