301 domain level redirects not working with rewrites

Hello, I’m trying to do 2 things with my _redirects. I want to A) redirect the netlify domain and a previous domain to a new domain https://www.sysdiagram.com, and B) I want to proxy all paths to my index.html file because it’s an SPA that I want to handle all the routing.

Here’s my _redirects file:

https://mellow-belekoy-9a875d.netlify.app https://www.sysdiagram.com 301
https://compass.halleyhares.ltd https://www.sysdiagram.com 301

/*   /index.html   200

https://www.sysdiagram.com works fine, and the last part works fine with the paths, but when I go to https://compass.halleyhares.ltd, it doesn’t 301 the URL. I’ve tried on various 301 testers online as well as 4G on my phone to get around any caching.

Both https://compass.halleyhares.ltd and https://www.sysdiagram.com are added as custom subdomains on my netlify account

Thanks in advance!

Hi @tomhalley, kindly try the code below in your _redirects file to see if it works. The difference is that an exclamation has been added after the 301 status code.

Change

https://compass.halleyhares.ltd https://www.sysdiagram.com 301

To

https://compass.halleyhares.ltd https://www.sysdiagram.com 301!

Let me know the outcome.

Thanks.

Hey @clarnx that worked! I’m not sure why it didn’t before, maybe because I was trying to do it at the same time the DNS was updating. I added the splat on too so it redirects with path included to end up with this

https://mellow-belekoy-9a875d.netlify.app/* https://www.sysdiagram.com/:splat 301!
https://compass.halleyhares.ltd/* https://www.sysdiagram.com/:splat 301!

/*   /index.html   200

Thanks for your help!

1 Like