---
name: "urlredir.conf"
section: "5"
platform: "linux"
package: "urlredir"
version: "2.03"
release: "Debian 3.0 (Woody)"
platforms: ["linux"]
url: "https://new.carta.tech/urlredir.conf"
---

# urlredir.conf(5)

configuration file for urlredir.

## NAME

urlredir.conf - configuration file for  **urlredir.**

## DESCRIPTION

The urlredir.conf file contains configuration information for urlredir, a url redirector for the  *squid* proxy server.

The urlredir.conf file is a free-form ASCII text file.  It is parsed by the recursive-descent parser build into urlredir.  The file may contain extra tabs and newlines for formatting purposes.  Keywords in the file are case-insensitive.  Comments may be placed anywhere within the file (except within quotes).  Comments begin with the # character and end at the end of the line.

The file is structured in a c-style format, with command lines starting subgroups (or functions - determined by enclosing braces {}), or terminated by ";"'s.

The configuration file contains two different command types:  search commands,  and action commands.

The search commands include:

```
	contains <key>... {
	hostcontain <key>... {
	pathcontains <key>... {
	exempt <key>... ;
	hostexempt <key>... ;
	pathexempt <key>... ;
```

The "contains" commands search the url's for any of the keys (more than one can be specified per line, note the ... notation), and then enter the subgroup (note the opening '{') if found.  The "exempt" commands also search for any of the keys, and if found exempt the url from any further searching.  The keys are specified as case insensitive *extended regular expressions* , as used in egrep.

The prefixes "host" and "path" imply that only the host or path of the url should be searched for the keys.

In addition, if the command "file" is given instead of a key, then the following key is interpreted as a file, from which keys are extracted, one per line.

```
	eg.   contains file "/var/lib/bann/banned.list" {
```

The current actions supported are as follows:

```
	redirect <url>... ;
	browser redirect <url>...;
	logfile filename;
	randomness 0..100;
```

All these commands only act upon a subgroup, except for logfile, which not only acts on a subgroup, but is inherited into all child subgroups (unless a new logfile is defined).

The redirect command specifies url's to redirect the request to.  This is  used inside a "contains" group, to redirect the request when there is a  matching key.  If more than one url is provided, a random one is chosen. There can also be multiple redirect lines in a group, with the same effect as a single line containing all the url's.

Browser redirect is a simple enhancement on redirect, that sends squid "302:\<url\>" instead, causing it to redirect the browser to that page.

The logfile entry specifies the file to log to when a redirect occurs.  A log entry of the following format is made:

```
      <date & time> <source of request> <url requested>
```

The active logfile is inherited into any child subgroups, unless the logfile is set within the child.  This means that you could set a logfile at the top of the config file, that would be used for all redirect actions.  This is  possible as the entire config file is considered as a "contains" class, with a key that always matches.

The randomness command specifies the percentage likelihood that a particular contains command applies, given that there is a matching key. This is useful for redirecting only part of the time.  This is 100% by  default.  If a command is not applied, then the url processing continues as if their had not been a key match at all.

## EXAMPLE

A typical urlredir.conf file might look something like this:

```
# Sample configuration for urlredir
# default log for redirect actions.
logfile "/var/log/squid/urlredir.log";
# Exempt all US government sites
hostexempt "\.gov$";
# Use each line in the file "/var/urlredir/exemptions" as a key
# to search on.
exempt file "/var/urlredir/exemptions";
# If a url contains the letters sex, redirect it to the Disney
# web site.
contains "sex" {
	redirect "http://www.disney.com";
}
# If a url path finishes in .mp3 or .wav, redirect it to either the
# sony web site, or to the polygram web site.  If it also contains
# xxx redirect to disney as well.  If it contains the word allow,
# exempt it.
pathcontains "\.mp3$" "\.wav$" {
	exempt "allow";
	hostcontains "xxx" {
		redirect "http://www.disney.com";
	}
	redirect "http://www.sony.com" "http://www.polygram.com";
}
# if the host contains advert, redirect to a local gif 50% of the time.
hostcontains "advert" {
	redirect "http://www.your.webserver.com/adreplacement.gif";
	randomness 50;
}
```

## SEE ALSO

[urlredir(1)](/urlredir/1.md),[regex(7)](/regex/7.md).

## PLEASE NOTE

The urlredir.conf file has changed since previous versions (\<1.3).  The keys now use regular expressions, so keys like "www.debian.org" should now be  written as "www\\.debian\\.org" .

The randomness command has also been changed.  Instead of randomly exempting the matched url, the randomness command randomly ignores the rule.

## AUTHOR

This manual page was written by Chris Leishman \<chris@ormond.unimelb.edu.au\>.
