Redirect subdomain to different domain

Hi there. I’ve seen a couple of posts similar to this but still can’t seem to get it working.

I’ve got a site that used to be on a subdomain of my personal website that now has its own domain. I want to 301 redirect the old subdomain to the new domain.

The site itself has a primary domain https://knowmyvalues.com/
The old subdomain is https://whataremyvalues.ryandunn.dev/

In the public folder of ryandunn.dev I have a _redirects file in the root with this:

http://whataremyvalues.ryandunn.dev/ https://knowmyvalues.com/ 301!
https://whataremyvalues.ryandunn.dev/ https://knowmyvalues.com/ 301!
http://whataremyvalues.ryandunn.dev/* https://knowmyvalues.com/:splat 301!
https://whataremyvalues.ryandunn.dev/* https://knowmyvalues.com/:splat 301!

This leaves me with a not found error when visiting the subdomain. So looking here:

For Netlify to redirect from a domain that is not the site’s main custom domain, the domain must be assigned to the site — probably as a domain alias or a branch subdomain.

When I set the subdomain as a domain alias it just acts as an alias, but I need it to redirect.

Not sure where to go from here, help much appreciated. Thanks!

Hey @ryandunn :wave:t2:

Welcome to the Netlify Community :slight_smile:

You will indeed want to set your subdomain as a domain alias. Once you have that, you should actually only need the fourth line from the four redirects you posted (_redirects format):

https://whataremyvalues.ryandunn.dev/* https://knowmyvalues.com/:splat 301!

because Netlify forces SSL anyway.

See if the combination of having the subdomain set as a Domain alias on ryandunn.dev and having the redirect in place does the trick :grin:

Also- I’ve seen lots of times where the _redirect file is in a src/ folder or something but doesn’t actually make its way to the publish/ (or etc.) folder, so take care to ensure that your _redirects file is actually making its way into your publish folder and that you build log confirms that 1 (or however many) redirect rules were processed


Jon

Ah perfect. I understand what I was doing wrong now. I had the subdomain as an alias of knowmyvalues.com and not of ryandunn.dev. That makes sense now.

Thanks!

1 Like