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.
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:
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:
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:
remove your _redirects file
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).
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.
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?
Yep! Fully agree with @Scott the /* vs. https://something.something.tld/* as the ‘from’ is a major difference! That code above should totally do it for you