Find And Replace

From EZProxyWiki
Revision as of 20:34, 14 January 2009 by Bob (Talk | contribs)

Jump to: navigation, search
  • Originally submitted by Ben Noeske, Harvard University Library, on June 13, 2003. Later updated by wiki editors.

The Find and Replace functionality was (I think) first introduced in the beta version dated 15 June 2001. The following information is based on testing I did with version 2.0h. The functionality was enhanced in version 5.0a, 31 March 2008.

This functionality allows you to instruct EZproxy to replace all occurrences of one arbitrary string in a given resource with another arbitrary string. It is commonly used to fix occurrences of native host/domain names that are not normally rewritten by EZproxy but need to be. Another common use is to change JavaScript that may be otherwise incompatible with EZproxy. It can also be used simply to change the wording on the user interfaces of resources – as done with OvidSP in this example.

See also the official OCLC Find page.


Basic usage

The Find and Replace lines are placed after the host/domain lists in a resource entry in the ezproxy.cfg file.

The Find line specifies the text to be replaced. The text on this line must match exactly the text in the page being proxied. That means the same number of spaces, the same use of case, etc. I do not believe there is anything like a wildcard matching operator or any other fancy pattern matching stuff.

Use the Replace line to specify the text that replaces the text on the Find line. The Replace line can take advantage of several special operators. More operators are listed at the official OCLC Find page.

  • ^H – inserts the proxy server's hostname (e.g. in this position.
  • ^D – inserts the proxy server's domain (e.g. in this position.
  • ^L – inserts the proxy server's domain with a leading period (e.g.
  • ^Psome_host_ezproxy_knows^ – placing ^P and ^ around some_host_ezproxy_knows will cause proxying to be applied to some_host_ezproxy_knows and the resultant string to be inserted. This is useful for making things look like EZproxy links that wouldn't otherwise be transformed by EZproxy (i.e. they don't appear as a link in an HREF tag or don't have a leading "http://" in the text of the page). For example:
T some db
Replace http://^^

Without this Find/Replace, EZproxy would leave untouched (it would look like in your browser, and you might wonder why it wasn't proxied until you saw the underlying coding). With the Find/Replace, EZproxy would make it look proxied (i.e. replacing with something like

Note: the some_host_ezproxy_knows doesn't have to belong to this same entry in the configuration file. In this example it could've actually been in the Find/Replace lines, as long as there was an entry somewhere in the cfg file that applied to It's not likely that there would be such a situation where you would really want to do that.

Look through the recommended database configurations at to see examples of these in use. Or, if you have a test version of EZproxy available, go ahead and play with them.

I don't know what the limits are for the lengths of strings in the Find/Replace lines. I've been able to use strings over a hundred characters long in a Find line without problem.

Multiple Find and Replace lines

Multiple Find and Replace lines can be included in each database configuration entry in the ezproxy.cfg file. Each Find/Replace pair will be applied to all pages that match that entry.

Note: Find/Replace does not cascade. If you have the following:

Find x-string
Replace y-string
Find y-string
Replace z-string

x-string would be replaced with y-string, but that y-string would not then be replaced with z-string. Of course, any y-string in the original page would be replaced with z-string.

Multiple matches

If there are two database entries that match a given page, the Find/Replace lines from the entry that comes first in the cfg file will be applied. Thus if a Find/Replace is not happening when you expect it to, you should check your config file for an earlier entry that matches the page you are looking at.


T some db
Replace http://^^

T some related db
# the following Find/Replace won't ever take place because all pages
# for this resource will actually be processed by the above entry for some db.
Find ''
Replace '^d'

Find and Replace occurs before proxying

If you were to cause a host in an HREF tag to be replaced with a host that is described by an entry somewhere in the ezproxy.cfg file, the string replacement will happen first and then that link will be transformed into its proxied form. Again, situations where you would want to do this are rare. I'm just including it for completeness of documentation.

Find/Replace can be a powerful tool, but it is also somewhat fragile because minor cosmetic changes by the resource vendor (the addition of an extra space, capitalizing something, etc.) that normally make no functional difference can cause a Find/Replace line to stop working. And like any extra processing you ask EZproxy to do, Find/Replace lines will create more load on your server. Of course, this probably won't be an issue unless you egregiously overuse the functionality, but it's something to keep way in the back of your mind.