redirect clients by sending a http status code 301 plus Location header
It supports matching "regular expressions":core_regex.html#core_regex and "substitution":core_pattern.html#core_pattern with captured substrings as well as other placeholders.
redirect clientsa 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":core_pattern.html#core_pattern.
* The "regular expressions":core_regex.html#core_regex 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.
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}";
}
}
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}";
}
}
setup {
module_load "mod_redirect";
}
redirect "^/old_url$" => "http://new.example.tld/url"
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}";
}