Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Essentially I want all requests for a website on my machine to be redirected to another website.

Example: You ping and gets pinged instead.

or a more useful example: Every request for automatically gets sent as

share|improve this question
This isn't even doable; DNS doesn't know or care about http vs. https. – derobert Sep 8 '09 at 3:04
If you could provide a more specific example of what you're trying to do and why you're trying to do it, it would be really helpful. As @derobert suggests, the two hypothetical cases you gave above are actually very different. Better to describe the problem you're trying to solve, and let us work with you to help solve it. – anschauung Sep 8 '09 at 3:46
my bad. Sorry about that. I think someone moved my post at stackoverflow to here, but before they did that I posted here on @Jed Smith's request. – Jay Sep 8 '09 at 14:01
@derobert I want to force SSL on sites that do not give the option to do so. So really just the second example. – Jay Sep 8 '09 at 14:04

You can redirect local stuff by modifying your /etc/hosts file.

However, what you want with http/https is different altogether.

One way of achieving this is to set up a local proxy with the necessary rules to do it. Keep in mind that your local proxy must be setup to ignore the hosts file and to resolve the ip addresses using an up-stream dns.

It goes something like this:

  1. Browser requests thru proxy.
  2. Proxy redirects to
  3. Browser requests thru proxy.
  4. Proxy ignores the contents of the hosts file.
  5. Proxy tunnels the connection through.
share|improve this answer

As noted in the comments, your two examples are totally different topics.

If I had to implement this for some reason (can't think of any right now), I would either edit my hosts file for the first example, if the list of necessary modifications is small or set up my own local DNS server to modify the responses.

For the second example, you would likely go with specifically configured proxy server which would rewrite requests as necessary. But note that this couldn't be done in a "catch-all"-fashion, as most sites don't offer SSL services, so just redirecting every query to a correspondent https variant won't work.

share|improve this answer
Right, basically I want to force SSL on the sites that have it available but give no option to force it – Jay Sep 8 '09 at 13:59

You can do some of this with the Squid cache-proxy program. The /etc/hosts trick won't work in this case since it isn't smart enough to do port-level redirection, such as needed for http: to https:. I believe the redirection rules in Squid are robust enough to write some of these filters. Install it on the local host and you can do intercept-proxies (I believe) so it would be invisible to the users.

This is an HTTP-level redirection, though, not an IP-level one. For pure IP you'll need something else. The /etc/hosts file can do a lot of it, but it's all or nothing. If you need to insert logic into what gets redirected more than IF Destination = A, SEND TO B then you'll need another package.

share|improve this answer

Edit your /etc/hosts:

#yahoo's IP address

As for the facebook thing, you will need to run a DNS server and set a webhop to https:// site instead of the http:// one.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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