How to Configure Proxy PAC Files

Creating a PAC File

  1. 1.

    Launch Notepad or a similar text editor. Create a new file and save it as “proxy.pac” to create an empty PAC file. Make sure that the text editor is set to display and save “all files” and not just “*.txt files,” as the latter can result in the file being saved as “proxy.pac.txt.”

  2. 2.

    Type the JavaScript line “function FindProxyForURL(url, host) {” (omit the quotation marks here and throughout) as the first line of the proxy.pac file to declare the FindProxyForURL function. The lines that follow it will define the function, giving instructions to the browser that encounters it.

  3. 3.

    Type “if (” as the second line of the file, assuming you wish to create a PAC file that checks to see whether a specific URL has been entered. If you wish to check whether one of several URLs have been entered, type “var proxy_1 = array(” instead, and place the URLs in quotes on the lines that follow with a comma after each; follow this with “);” to close the array and “for (var i = 0, var count = proxy_1.length; i < length; i++) {" to establish a check of each URL, then add your "if(" declaration. An example of an array list would look like this:

    var proxy_1 = array( “”, “”, “”, ); for (var i = 0, var count = proxy_1.length; i < length; i++) {

  4. 4.

    Type “localHostOrDomainIs(host, “”)” (without the external quotes) on the next line to establish a condition for your “if” statement, replacing “” with the URL of the website that you're checking for. If using an array declaration, this should be typed as “localHostOrDomainIs(host, proxy_1[i])” instead. Follow this with “) {” on the next line.

  5. 5.

    Type “return “PROXY″;” on the next line, substituting the URL of your proxy website for “” and the port number of that proxy for “8080.” This instructs the browser to use a proxy when visiting the site and provides settings for the specific proxy it should use.

  6. 6.

    Type “} else {” on the next line to close the “if” statement and establish an alternative option for navigation requests that don't meet the “if” statement. If you wish to add additional conditions or arrays you can use “elseif” instead of “else,” following the same conditional pattern to establish your next set of “if” conditions. An “else” statement should be added after any additional conditions that you create.


  7. 7.

    Type “return “DIRECT”;” on the line after your “else” statement, instructing the browser to allow direct access to the server for other URLs instead of using a proxy. Follow it with two lines containing nothing but “}” to close both the “else” statement and your initial function declaration. Save the file, then upload it to the root directory of your server.

  8. 8.

    Open the .htaccess file on your server and add the line “AddType application/x-ns-proxy-autoconfig .pac” to make sure the server recognizes that a PAC file is present. Save the .htaccess file to finalize the configuration of your server to use the proxy auto-config file.


Article post on:

Leave a Comment

Your email address will not be published. Required fields are marked *