There's a similar question to this, but that one only says that you need to setup a webserver, but doesn't elaborate on that and is probably something that I'm not looking for. Another one was over here, but dealt with linux and programatically redirect

What I want to do is if a person on my windows computer tries to access a certain url, like "google.com/something?hello=1234", it would map it to "". I tried doing this on my host file without success (even without the get parameters): (ip of site) (local ip)

  • if the hostsfile didn't work as you expected maybe you have tested it before cleaning up the browsers cache also you may have missed to flush the dns cachem. if that doesn't help you - you may need to set up a own dns server on your pc or use a internet proxy. – konqui Jun 26 '14 at 4:03
  • @konqui 'use an internet proxy' is a bit non-descriptive. If you know how to configure squid to get redirects for specific URLs then perhaps post that as an answer – barlop Jun 26 '14 at 4:54
  • @barlop with proxy i didn't mean a squid butt it may still work have a look here wiki.squid-cache.org/Features/Redirectors - i personally don't use a squid i have thought of a simple proxy application/webservice written in java or so which will act like a man in the middle and redirect all request of a sertain url to an ip as the idea is in here stackoverflow.com/questions/19212830/… – konqui Jun 26 '14 at 5:02

say the url is http://google.com/something?hello=1234 put in your hosts file google.com If your URL is http://www.google.com/something?hello=1234 put in your hosts file www.google.com you don't include anything after the domain name in the hosts file. But you do include the exact whole domain

do `wget www.google.com/abcdefg?a=b -O index.html -d'

then look at the headers and you will see if it's going to and see a GET header saying /abcdefg and any parameters should be there.

The hosts file is I suppose, meant to be like a quick DNS cache it at least works like that, so you don't specify anything after the domain in there, and also it won't remove it from the URL you enter into the browser. It just changes the domain into the specified IP and leaves the rest, which I suppose is what you want.

But you may want a web server that you configure, because if you do wget www.google.com/abcdefg and it does and that's your router configuration it's like accessing your router without entering user/pass so you might just get an unauthorized page back from your router. Besides the fact that there is no abcdefg directory on there.

You wrote " I tried doing this on my host file without success (even without the get parameters)" <-- that should read hosts file. And you should get an effect and understand what the hosts file means for the browser.

But if you want to redirect on a way that is conditional not on the domain, but on the directory/parameters, or on the domain+directory/parameters, such that the same domain can redirect you to different IPs, based on the stuff after the domin in the http request, then the hosts file won't do that and i'm not sure what will. You could look into if squid can but you might want to set it up as a transparent proxy as well as seeing if it can redirect in the manner that you want.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.