Redirecting domain alias

Hello!

My site’s Primary Domain is kieran-mcguire.uk/. Its Default Subdomain is kieran-mcguire.netlify.app/.

I’m trying to redirect another domain - kieranmcguire.uk/ - to my primary domain.

I’ve added kieranmcguire.uk/ as a Domain Alias to the site in Netlify.

In my domain management tool, DNSimple, I have these records (among others):

The nameservers are DNSimple’s, I am not using Netlify DNS.

In my netlify.toml file, I have these redirects rules near the top. They are not limited to any context, as that seemed to not work either and I’m happy for them to apply all the time.

[[redirects]]
  from = "kieranmcguire.uk/*"
  to = "kieran-mcguire.uk/:splat"
  status = "301"
  force = "true"
[[redirects]]
  from = "www.kieranmcguire.uk/*"
  to = "kieran-mcguire.uk/:splat"
  status = "301"
  force = "true"
[[redirects]]
  from = "kieran-mcguire.netlify.app"
  to = "kieran-mcguire.uk/"
  status = 301
  force = true

My expectation was that this domain would point to the Netlify site, like a normal domain, but that Netlify would then follow these rules and redirect me to https://kieran-mcguire.uk/, always.

This is not happening.

Any ideas? What have I missed?

(I couldn’t post this with so many links in it, so have stripped out the HTTPS parts. Assume every link is HTTPS.)

Hi @kmcguire

Your Netlify domain does redirect, but only at the root (e.g. https://kieran-mcguire.netlify.app/posts/adding-security-headers-through-netlify/ does not) because you haven’t added and /*/:splat

In all cases though, try prepend https:// for both to and from rules in all cases as demonstrated in the Domain-level redirects docs. Also no need to wrap the 301 or true in "

[[redirects]]
  from = "https://kieranmcguire.uk/*"
  to = "https://kieran-mcguire.uk/:splat"
  status = 301
  force = true
[[redirects]]
  from = "https://www.kieranmcguire.uk/*"
  to = "https://kieran-mcguire.uk/:splat"
  status = 301
  force = true
[[redirects]]
  from = "https://kieran-mcguire.netlify.app/*"
  to = "https://kieran-mcguire.uk/:splat"
  status = 301
  force = true

Hope this helps.

1 Like

That does help! I didn’t even spot the missing wildcard from the Netlify Subdomain rule.

And yep, I missed the quotation marks around the 301 and true values, they shouldn’t have been there.

All working fine now.

Thank you!

1 Like