Arjun Sajeev

Redirecting domains using Netlify

I recently decided to move one of my projects to a new domain. Since the old domain was on Namecheap, I thought about using the BasicDNS service provided by Namecheap. I had faced issues with Namecheap DNS in the past and the basic version of Namecheap DNS did not seem to offer any uptime guarantees. Since the project was hosted on Netlify, I decided to use Netlify DNS to redirect requests from the old domain to the new domain. First I added the domain to Netlify using the UI and updated the DNS settings on Namecheap to point to Netlify's DNS servers. Then I needed to setup a wildcard redirect on Netlify. Setting this up on Netlify was not exactly straightforward and that's why I decided to write this post 😄.

Netlify lets you configure redirects using an _redirects file or using netlify.toml. I decided to use an _redirects file. I created a new git repository with an empty _redirects file and pushed that to Github. Then I linked my old domain to this repo using the UI.

https://old.com https://new.com 301!
https://old.com/* https://new.com/:splat 301!

Adding the lines above to the _redirects file and redeploying did the trick. All the links to the old domain were being redirected successfully to the new domain.