mod_redirect

mod_redirect redirect clients by sending a http status code 301 plus Location header

It supports matching regular expressions and substitution with captured substrings as well as other placeholders.

redirect (action)

redirect clients

redirect rule;
rule
a simple target string or one rule, mapping a regular expression to a target string, or a list of rules.
  • The target string is a pattern.
  • The regular expressions are used to match the request path (always starts with “/”!)
  • If a list of rules is given, redirect stops on the first match.
  • By default the target string is interpreted as absolute uri; if it starts with ‘?’ it will replace the query string, if it starts with ‘/’ it will replace the current path, and if it starts with ‘./’ it is interpreted relative to the current “directory” in the path.

Example: redirect always (http to https)

setup {
	module_load "mod_redirect";
}
if request.scheme == "http" {
	if request.query == "" {
		redirect "https://%{request.host}%{enc:request.path}";
	} else {
		redirect "https://%{request.host}%{enc:request.path}?%{request.query}";
	}
}

Example: redirect always (prepend www)

setup {
	module_load "mod_redirect";
}
if request.host !~ "^www\.(.*)$" {
	if request.query == "" {
		redirect "http://www.%{request.host}%{enc:request.path}";
	} else {
		redirect "http://www.%{request.host}%{enc:request.path}?%{request.query}";
	}
}

Example: redirect if match

setup {
	module_load "mod_redirect";
}
redirect "^/old_url$" => "http://new.example.tld/url"

Example

redirect all non www. requests. for example: foo.tld/bar?x=y to www.foo.tld/bar?x=y

if request.host !~ "^www\.(.*)$" {
	redirect "." => "http://www.%1/$0?%{request.query}";
}

redirect.debug (option)

enable debug output

redirect.debug value;
Default value: false