Setting up proxy auto configuration with Apache

Proxy auto configuration (PAC) allows browsers to use javascript logic to decide how to access a website.

To setup proxy auto configuration, setup apache with the following config:

#proxy auto configuration
Redirect /wpad.dat http://yourhostname/pac/

<Location /pac>
    DirectoryIndex proxy.pac
    ForceType application/x-ns-proxy-autoconfig

Then create the file proxy.pac in the /pac dir of your web root:

//proxy auto config
function FindProxyForURL(url, host) {
    //name only
    if (isPlainHostName(host))
        return "DIRECT";
    //without dns
    if (!isResolvable(host))
        return "DIRECT";
    //internal ips
    if(isInNet(host, "", ""))
        return "DIRECT";
    //everything else goes through the proxy
    return "PROXY";

Put the above PAC address into your browser and the javascript code will be downloaded once only and start working.

Last updated: 08/07/2008