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.
-
you want to redirect it for your local machine (outgoing) or for all?– RaystafarianJul 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?– PaulJul 24, 2013 at 14:05
1 Answer
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.