Redirect file not processed

I’ve built a simple bootstrap site, deployed form git. Hand tooled, so not using anything like Jekyll, hugo etc.

Looking to do a redirect of the default subdomain. _redirects.txt is in the root, but the deploy message is saying that no redirects are processed. If I download the deploy, the redirects file is there.

Syntax is here. Probably a typo or something stupid like that, but can’t seem to see the woods for the trees on this one.

    # Redirect default Netlify subdomain to primary domain
https://dazzling-lovelace-dfccb9.netlify.app/* https://www.kindcarecornwall.co.uk/:splat 301!

Hey @rossjones and welcome to the forum :wave:

A few changes to make:

  • remove the .txt extension from your _redirects file, so just _redirects
  • and then the rule itself is close, but should instead be:
    /* https://www.kindcarecornwall.co.uk/:splat 301!

And one thing to check: you mentioned that your _redirects file is in your directory root. It needs to be in your publish directory- these may be the same, but if you have a build process that outputs a directory to publish, then you’ll have to copy the file from the root into that directory (or use the netlify.toml file instead).

Here are our docs on redirects where we cover file syntax and location:

Hope this helps!

Thanks @jen

Those changes got the build to recognise the redirects! :sunglasses: But if I put the URL in it doesn’t redirect to the custom domain. :crying_cat_face:

The directory structure is pretty basic and the redirects file is in the same folder as the index.

I dug into the docs, but can’t find a walkthrough on accessing the .toml file. Is there a link that I can look over?

Alright, makin progress! Here are the docs on the netlify.toml:

This would be called netlify.toml and would go in your directory root. A very basic one would be:

[build]
  publish = "..." <--- whatever directory is published
  command = "..." <--- build command if you have a build step
[[redirects]]
  from = "/*"
  to = "https://www.kindcarecornwall.co.uk/:splat"
  status = 301
  force = true

So this is for anyone who’s a bit green like me and wants to get this set up.

Having multiple domains runs the risk of Google penalising your site for duplicate content. For some this isn’t an issue, but if you’re looking at getting ranked, it’s important you add a redirect to your pre-assigned netlify domain.

Despite the _redirects file being correctly processed, my site still wasn’t redirecting. So I created a netlify.toml file (yes, you have to create this in your favourite code editor) and added the redirects in that. Success!

I’ve still got the _redirects file in the root just in case, but it seems like .toml is the way to go.

Those two files can and will “fight” - so you should just use the one, @rossjones! The reason your _redirects file did not work right is because your syntax was wrong:

https://dazzling-lovelace-dfccb9.netlify.app/* /* https://www.kindcarecornwall.co.uk/:splat 301!

has an extra “/*” in the middle that is making it do the wrong thing.

Your netlify.toml was NOT created per Jen’s advice - you left off some key elements:

Jen:

  from = "/*"
  to = "https://www.kindcarecornwall.co.uk/:splat"

You:

 from = "https://dazzling-lovelace-dfccb9.netlify.app"
 to = "https://www.kindcarecornwall.co.uk"

…so I recommend that you:

  1. remove your _redirects file
  2. update the toml file to match Jen’s suggestion

And then everything will REALLY work as you intend and be configured correctly in our database. The current configuration is probably having some unexpected side effects due to the syntax error so I advise that you modify those two things (together).

@fool @jen - Your support has been par excellence :100:

I misunderstood @jen original instruction!

Just in case anyone stumbles across this thread, your redirect playground really helps
https://play.netlify.com/redirects

Removing _redirects and adding the catchall redirect to the .toml file created a too many redirects error. So I’ve added the original domain for the time being until I figure out what’s happening.

1 Like

Hey @rossjones :wave:t2:

I was going to add a thought or two to the mix here because you said

So I’ve added the original domain for the time being until I figure out what’s happening.

Which made me think that your issue is unresolved, but upon poking at your site, it appears your redirect from your netlify subdomain to your primary domain is working fine. Are you still having any issues?


Jon

Thanks for reaching out @jonsully.

It’s working but only on that domain. So if you went to
KindCare - Homecare in Helston and the surrounding areas | Our Care Services it won’t redirect.

That’s because my .toml file reads

[[redirects]]
  from = "https://dazzling-lovelace-dfccb9.netlify.app/"
  to = "https://www.kindcarecornwall.co.uk"
  status = 301
  force = true

If I use this

[[redirects]]
  from = "/*"
  to = "https://www.kindcarecornwall.co.uk"
  status = 301
  force = true

I get the Too Many Redirects error come up in the browser.

I’ve got ALIAS records for @ , www , and * in my DNS all with the dazzling-lovelace-dfccb9.netlify.app value.

It’s only a small site, so I could theoretically list every page with their corresponding redirect.

[[redirects]]
  from = "https://dazzling-lovelace-dfccb9.netlify.app/*"
  to = "https://www.kindcarecornwall.co.uk/:splat"
  status = 301
  force = true

Try that on for size :slight_smile: Note the /* and /:splat :+1: which are explained here:

2 Likes

Yep! Fully agree with @Scott :grin: the /* vs. https://something.something.tld/* as the ‘from’ is a major difference! That code above should totally do it for you :+1:t2:


Jon

1 Like

@jonsully @Scott :bowing_man: :tada:

2 Likes