Prev: Next: , Up: Simple Proxy[Contents][Index]


4.6 Redirects

Apart from regular backends introduced in previous sections, pound provides also several special or internal backends. As their name implies, such backends handle requests and generate responses internally, without forwarding them to any external entities.

One of such internal backends is Redirect. It generates responses redirecting the client to another location. The statement takes two arguments: a three-digit HTTP status code to return, and the URL to redirect to:

Service
    Redirect 301 "https://www.gnu.org"
End

Allowed values for the status code are 301, 302, 303, 307 and 308. This argument is optional: if omitted, 302 is used.

If the URL argument has no path component (as in the example above), then the path (and query, if present) components from the original request will be appended to it. For example, if the original URL were ‘http://example.com/software’, the service above would redirect it ‘https://www.gnu.org/software’.

Otherwise, if the path component is present in the URL argument (even if it is a mere ‘/’), then the URL is used as is. For example, the following will drop any path and query components from the URL when redirecting:

Redirect 301 "https://www.gnu.org/"

The URL argument is subject to backreference expansion and request accessor interpretation (see Request modifications). If any of these are actually used, the above logic is disabled.

String expansions make it possible to implement complex redirects. For example, the following redirect swaps the first two path components of the original URL:

Service
    URL "^/([^/]+)/([^/]+)(/.*)?"
    Redirect "http://%[host]/$2/$1$3"
End

The following is a standard paradigm for redirecting requests from HTTP to HTTPS:

Service
    Redirect 301 "https://%[host]%[url]"
End

Prev: Next: , Up: Simple Proxy[Contents][Index]