ManticMoo.COM All Articles Jeff's Articles
Jeffrey P. Bigham

Redirecting Transparently with Apache httpd and mod_proxy

Jeffrey P. Bigham

Related Ads

For months I've been trying to get Apache httpd to do transparent redirects. The basic idea is that if you're connected to my proxy then you can navigate to http://www.yahoo.com and be shown http://www.pornpalace.com instead. I have a legitimate work reason to do want to do this, but its potential for hilarious mayhem has not escaped me. I suppose it could also be used for phishing, but if someone has access to change which proxy you're accessing the Internet with then you have bigger problems.

Although my route to discovering the solution was circuitous, it revolves around the simple way that local filenames and proxy addresses are differentiated internally in httpd. Filenames are just represented as a filename string while proxies are the whole proxy address prefixed with "proxy:". If it's a directory address then you'll have to make sure that it ends with a slash "/" or you'll get an improperly formatted request error.

Once we know what we need to do, we can use the mod_rewrite module in Apache to accomplish it. For example, to redirect all requests made to your server to http://www.yahoo.com/, simply add the following line to your httpd.conf file:


RewriteEngine On
RewriteRule	^.*$	proxy:http://www.yahoo.com/

This will transparently redirect all requests to Yahoo. You can also use the other standard rewriting directives, such as RewriteRule, RewriteBase, RewriteCond, etc. This took me forever to find - hopefully you found this article quickly and were spared the trouble.

Jeffrey P. Bigham
ManticMoo.COM All Articles Jeff's Articles