Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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.

share|improve this question
    
you want to redirect it for your local machine (outgoing) or for all? –  Raystafarian Jul 24 '13 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 '13 at 14:05

1 Answer 1

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.

share|improve this answer

Your Answer

 
discard

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.