Configuration

Files

In the ./config/ folder are json files. Copy the dist files to the same filename without “.dist”

  • redirects_<FQDN>.json - Config with redirects per domain
  • aliases.json - list of domain aliases

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

Let’s start with an example for a redirects_<FQDN>.json:

{
    "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" },
        ".*":       {"code": 301, "target": "https://www2.example.com" }
    }
}

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.

Section “direct”

This section has keys für direct matches to a webservice like location as string eg. “/mail”. This entry will match for a request to location /mail only - but not /mail2.

Section “regex”

This section has keys für direct matches to a webservice like location as regex eg. “^/mail” This entry will match for a request to all locations starting with /mail: /mail and /mail2 as well. Use the dollar sign to define

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.

Define redirect

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)

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 a written redirect_<FQDN>.json already.

The existance of a redirect config has higher priority than an entry in the aliases config.