Question

is it possible to automatically route a local path like localhost/pathToResource to a remote source <serverIP>/pathToResource in OSX (Mountain Lion)?

As I understand, you cannot do this in the hosts file, because it only maps DNS names to IPs.

Thank you!

Was it helpful?

Solution

You need to run a web server (assuming we're talking about HTTP requests) on localhost which redirects or proxies requests to pathToResource to the remote path. For example, create an .htaccess file in the document root of your web server (~/Sites for the built-in Apache server) with something like:

RewriteEngine On

RewriteRule ^pathToResource$ http://<serverIp>/pathToResource [R]

# or

RewriteRule ^pathToResource$ http://<serverIp>/pathToResource [P]

The first rule will redirect any request to the remote URL (clients are instructed to visit the other URL), the second one will proxy it (get the data and return it as if the remote resource was hosted locally).

OTHER TIPS

Thanks to decezes help, I got it working. However, I ended up not using the .htaccess and Apaches RewriteEngine, but configuring a ProxyPassand ProxyPassReversein the httpd.conf.

ProxyRemote http http://<your-componay-proxy>
ProxyPass /service http://<remoteIP>:<port>/webservice.svc
ProxyPassReverse /service http://<remoteIP>:<port>/webservice.svc

This also works like a charm, but without the regexes.

But decezes answer is also working, so I marked his answer as correct.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top