Table of Contents
Configuration
In the ./config/ folder are json files. Copy the dist files to the same filename without “.dist”
- redirects_[FQDN].json -
- aliases.json -
You can create multipe redirect files redirects_[FQDN].json
. We suggest to use the main domain as FQDN.
If you have multiple domains that should use exactly the same redirects then use the aliases.json
.
Other requirements:
- In the DNS you must point each domain to the redirect website.
- In the apache web with multiple vhosts: add the need a server alias to process the hostname in the wanted vhost
Redirects
There are 2 required sections to define redirects:
- direct
- regex
The section “direct” will be scanned first and has priority. The json will be read into a hash … if you define a direct rule twice then the last rule will win.
If no direct rule matches the regex section will be scanned. Winner is the first matching regex.
If no rule matches a 404 will be shown.
Hint: if you set regex “.*” as last entry it works as a catchall for unmatched requests and you can define a default redirect target instead of showing a 404.
Both redirect section contain a redirect definition
- code - http status code for redirection
- target - target url of the redirect
Status codes
- 301 => ‘Moved Permanently’; the url is outdated
- 307 => ‘Temporary Redirect’; the url is valid
- 308 => ‘Permanent Redirect’; the url is outdated
Suggestion for redirection lifecycle:
- an active redirect (i.e. a campaign) use code 307
- if the redirect has finished its life, switch the code to 308 or 301.
- remove the redirect (which results into 404)
Example:
{
"direct":{
"heise": {"code": 307, "target": "https://www.heise.de" }
},
"regex":{
"^$": {"code": 307, "target": "https://www.iml.unibe.ch" },
"^ax.l.*": {"code": 307, "target": "https://www.axel-hahn.de" }
}
}
Server aliases
If you have multiple domains with the same rules you can define aliases.
Example:
{
"www.example.com": "example.com",
"zzz-domainname": "existing-host-with-redirect-config"
}
The key is the name of the alias. The value is a domain for that was written a redirect_[hostname].json already.
The existance of a redirect config has higher priority than an entry in the aliases config.