2

I want to redirect "www.example.com/sub-dir" to a specific IP, using Windows hosts file. Not just the domain but the domain + sub directory.

2
  • you want to redirect it for your local machine (outgoing) or for all? Jul 24, 2013 at 14:01
  • If you add the domain to the hosts file, the GET request (including the entire URL, including the subdir) will be passed to the server at the IP address. Is something not working?
    – Paul
    Jul 24, 2013 at 14:05

1 Answer 1

2

You can't; as with any DNS resolver, entries in the hosts file can only map an IP address to a domain, and attempting to include a directory path will result in an unreadable entry which will probably be ignored.

What you can do is use an HTTP server, such as Apache, to implement the redirect; in Apache this can be done by means of a Redirect directive in the <Directory> configuration entry for the directory in question, or possibly by means of ProxyPass or ProxyReverse directives if you want the redirect to be transparent.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .