Achieve wildcard custom domain via Automatic Proxy Configuration

Update: This method seriously screws up apache server variables, namely, REQUEST_URI and DOCUMENT_ROOT. It is recommmended to only use this pac method when you know you don’t need correct REQUEST_URI and DOCUMENT_ROOT.

This allows to point multiple wildcard domain names (canonical or not) to a particular ip or hostname.

First create a Automatic Proxy Configuration file say wildcard.pac, which is basically a javascript file:

function FindProxyForURL(url, host)
{
    if (dnsDomainIs(host, ".customhost.local")) {
        return "PROXY customhost";
    }
 
    return "DIRECT";
}

Note:
“.customhost.local” is basically the pattern to detect
The “customhost” in “return “PROXY customhost”;” is whatever solvable hostname you want, or it can be an ip.

You can use this to config multiple local fake domain names for development purpose, pointing them (e.g. project1.myhost.local, project2.myhost.local to an apache server at 192.168.1.2).

Now to load this pac file, each browser/os is slightly different.
Safari/IE/Chrome: use system network setting, just find the Automatic Proxy Configuration and load the pac file just created.
Firefox/Opera: use their own network config in Preferences

Leave a Reply