DEV Community

Cover image for How to Redirect a domain only using DNS records
Wildan Mubarok
Wildan Mubarok

Posted on • Updated on • Originally published at blog.wellosoft.net

How to Redirect a domain only using DNS records

At some point in time to want to move your website to a new domain address but don't want people with existing URL links to your old domain to find your content is no longer found, so then you need to set up a redirect link.

I thought this was easy, but turns out it isn't. You need a separate server for that. Who would want to purchase additional bucks just to set up a server to redirect links?

So let's meet forwarddomain.net, a simple redirect service.

All you need to do to use this service is to add CNAME and some TXT records, like this:

www.old.com     IN    CNAME   r.forwarddomain.net
_.www.old.com   IN    TXT     forward-domain=https://old.com/*
Enter fullscreen mode Exit fullscreen mode

This will redirect all links from www.old.com to old.com. You can also redirect other domains, just change the forward-domain= part.

In case you want to redirect a root or apex domain, you can't do that with CNAME, so you can use an A record that directly bind to the IP address of this service:

old.com     IN    A       167.172.5.31
_.old.com   IN    TXT     forward-domain=https://new.net/*
Enter fullscreen mode Exit fullscreen mode

That's it! this will redirect all links from old.com to new.net. Note the * part? it means also forward URL paths and GET query data.

What about the email? It is used to signing HTTPS certificates from Let's Encrypt. This should be your valid public email. HTTPS redirection would not work without it.

This is all you need to be able to set up domain redirection of your old domain. No coding required, no registration required, completely free and anonymous. You can also see the GitHub repo since it's an open-source project anyway.

EDIT 2021-09-21: This post is updated for v2.0 changes

Latest comments (3)

Collapse
 
wpsyed profile image
Syed Saadullah Shah

I appreciate !

Collapse
 
cicirello profile image
Vincent A. Cicirello

You can probably do this directly with your domain provider without involving a 3rd party. For example, Google Domains has domain redirection. I imagine most domain providers support that. Is there an advantage to using this forwarddomain service instead of your domain provider?

Collapse
 
willnode profile image
Wildan Mubarok • Edited

Automation. I mean if your domain nameserver is not set to its own domain providers, you'll lose this feature, there are many cases why you want to manage your own DNS or giving it to third-party (CloudFlare or something else) and it happens to my situation a lot.