HTTP Redirect
You cannot perform HTTP redirects in the DNS itself. A webserver is required for this. To simplify HTTP redirects, Ops One offers a redirect service. The service is free and takes care of the redirect. The only thing you have to do is create an A/AAAA and TXT record.
Minimum Example
Example with A, AAAA and TXT record with all required keys:
blog.example.org. IN A 185.169.84.4
blog.example.org. IN AAAA 2a04:503:0:1023::4
blog.example.org. IN TXT v=opsone-redirect-v1;destination=https://example.org/;contact=john@example.com
How-To
Add the TXT record for the domain you want to redirect, see the example above
Add the A and AAAA records for the same domain
Wait for the DNS changes to propagate
Check if the redirect works
Some browsers heavily cache redirects. If you have problems, try a different browser or clear the cache.
The easiest way to check the redirect is to use command line tool like curl
or wget
.
Example:
$ curl --head https://blog.example.org
location: https://example.org/
Specification
Key |
Required |
Description |
---|---|---|
|
Yes |
Used for versioning |
|
Yes |
The URL to redirect to |
|
Yes |
Your email address |
|
No |
The HTTP status code to use for the redirect |
|
No |
Add original request path and query string |
v (required)
Used for versioning
Currently only
opsone-redirect-v1
is supported
destination (required)
The URL to redirect to
Must start with
http://
orhttps://
contact (required)
Your email address
Required in case we need to contact you
code (optional)
The HTTP status code to use for the redirect
Defaults to
302
if not specified
preserve-path (optional)
Add original request path and query string to destination URL
If destination URL already contains a path, the original request path will be appended
Example #1, destination to another host:
blog.example.org. IN TXT v=opsone-redirect-v1;preserve-path;destination=https://example.org/;contact=john@example.com
Configured like this, requests to blog.example.org/123
will be redirected to example.org/123
(where /123
is preserved).
Example #2, destination to another host with a specific path:
blog.example.org. IN TXT v=opsone-redirect-v1;preserve-path;destination=https://example.org/page;contact=john@example.com
Configured like this, requests to blog.example.org/123
will be redirected to example.org/page/123
(where 123
is preserved from the original request and page
from the destination).
SSL Certificate
The redirect service automatically uses a Let’s Encrypt certificate. The certificate is issued with the first request, which is why the first request takes a little longer to complete. If the certificate cannot be issued, you can check your (sub)domain for setup errors with letsdebug.net.
CNAME Delegation
You can also use a CNAME record to delegate the redirect to another host.
For example, if you have already set up a redirect at blog.example.org
(see example above) and also want to redirect docs.example.org
to the same destination, you can setup a CNAME record:
docs.example.org. IN CNAME blog.example.org.
Now docs.example.org
behaves like blog.example.org
and redirects to the same destination.
Known Errors
If you have been redirected here, you will find an error code in the address bar.
Please check that the TXT record is correct and available.
You can use dig
or nslookup
to check the TXT record.
Example:
$ dig blog.example.org txt
blog.example.org. 300 IN TXT "v=opsone-redirect-v1;destination=https://example.org/;contact=john@example.com"
In the DNS response you also see the Time to Live (300 seconds in this case). You need to wait at least this time for the changes to propagate.
Error 42
No host header found.
Error 43
No txt record found.
Error 44
No txt record with string opsone-redirect-v1
found.
Error 45
More then one TXT record with string opsone-redirect-v1
found.
Error 46
No destination
found.
Error 47
No contact
found.