Redirector service
The redirector service is a web site that redirects users to updated URLs. It is designed to redirect requests for old domains to updated links.
Configuration
The configuration is hosted in a Git repository at gitlab.sikt.no. To add or update a site, clone that repository, and edit config.json.
The available options are:
acme
(Optional): Whether cert-manager should create a Let's Encrypt cert for the redirect entry. The default is true
.
default
(optional): The default URL to redirect to if none of the entries in redirects
match. If default
is not set, a 404 Not Found will be returned if no redirects match.
Note: The path from the original URL is not included in the redirect to the default URL. I.e. if the user requests https://www.example.org/topic.html, topic.html is not added to the default URL when redirecting.
hostname
(Mandatory): The FQDN of the domain the redirect is for.
https
(Mandatory): Set to true
to enable https for this site.
permanent
(Optional): Whether we should send permanent or temporary redirects. The default is false
, i.e. send temporary redirects.
redirects
(Optional): This is an array of path/regex-based redirects. Each element consists of the following:
target
(Mandatory): The URL that path should redirect to.include_query_string
(Optional): Set tofalse
to remove the query string when redirecting. The default is to include the query string.path
: The path prefix that we should match.regex
: The regular expression to match against the URL.
Either path
or regex
must be specified.
(Remember order matters for redirects
. To be able to redirect
/tv/kanaler.html
correctly it should be before redirect of /tv
.)
Examples
Minimal example
Redirect all URLS on old.example.com
to https://new.example.com/
.
Note:
This example does not preserve the path of the URL.
I.e. https://old.example.com/some/path
will redirect to https://new.example.com/
.
{
"hostname": "old.example.com",
"https": true,
"default": "https://new.example.com/"
}
Redirect preserving the path
Use a path-based redirect in the redirects
section to preserve the path in the URL.
This will redirect https://old.example.com/some/path
to https://new.example.com/some/path
.
{
"hostname": "old.example.com",
"https": true,
"redirects": [
{
"path": "/",
"target": "https://new.example.com"
}
]
}
Regex based redirects
Use a regular expressions for advanced URL rewriting.
This example uses a regular expression to remove .html
from all URLs, with a fallback to a normal path-based redirect if the URL does not end with .html
.
{
"hostname": "old.example.com",
"https": true,
"redirects": [
{
"regex": "^/(?P<path>.+)\\.html$",
"target": "https://new.example.com/{path}"
},
{
"path": "/",
"target": "https://new.example.com"
}
]
}
Deploying
Once you have made a configuration change, you can deploy it by pushing the change to the Git repository.
DNS setup
The domain names must be manually registered in DNS.
These should be in the form of CNAME records pointing to redirector.uninett.no
:
webmail.uninett.no. IN CNAME redirector.uninett.no.
SSL certificates
The Redirector runs in the Platon PaaS cluster and certificates are handled by cert-manager
which issues Lets Encrypt certificates.