Redirect don't work when you visit your site for the first time

I set redirects with the netlify.toml and using a cookie to define the country code (nf_country).
The redirects work, but with your second visit within the session. The first visit returns 404 (this page doesn’t exists). Unfortunately, it has an impact on our SEO results. The URL returns 404 in the SEO crawlers instead of the redirected site.

test example:

[[redirects]]
from = "/angstpatienten/"
to = "https://<here_is_my_original_domain>.es"       
status = 301
force = true
conditions = {Country = ["ES"]} 

hi there, before we dig in, did you see this brand new guide on debugging redirects?

I strongly suggest you give it a thorough read through and see if this fixes your problem:

if not, please post again, and we’ll try and troubleshoot.

Hi Perry!
Thank you for the support guide. Unfortunately, I couldn’t find a way out :frowning:
Maybe some additional info that could help you in the investigation:

  • we are using Gatsby,
  • I am trying to redirect to our different project on Netlify. But the domain for this project we are trying to redirect to is a custom one and is proxying through Cloudfront to Netlify.

I don’t understand why the redirect doesn’t work on the first visit (within one session), but works on the refresh.

You’ll want to make sure that the rule you have specified in your first post is at the top of your redirects file. Then, below it, I believe you’ll want a SPA redirect:

Ok, so today it started working in the browser. Unfortunately SEO tools still returns 404.
The order of the redirect is correct. We are redirecting to a different domain and the examples for SPA are pointing to the same one, so I guess are not for us, but I also tried with /index.html. I don’t want to redirect all the subpages from 404 to the custom domain. Only some particular one. So I also checked this Rewrites and proxies | Netlify Docs

I also tried with the /index.html slug

[[redirects]]
from = "/angstpatienten/"
to = "https://<here_is_my_original_domain>.es/index.html"       
status = 301
force = true
conditions = {Country = ["ES"]} 

The SEO tools I checked:

https://httpstatus.io/

Are you trying to get a lot of pages to redirect, or just one? I see you mentioned subpages.

If you want, for example, /angstpatienten/page to redirect, you’ll want to update the rule to

from = "/angstpatienten/*"

You can check out what the asterisks can do (a splat) in our docs; there’s also our redirects support guide for a bit of further reading!

No, I am redirecting one per redirect. But we have many, almost the same redirects for different pages.
We are also using splat in different redirect, but this is not this case :frowning:

If you wouldn’t mind getting an x-nf-request-id for a request made on your site, I can gather the site information and take a look at your actual redirects and traffic :slight_smile:

ffb6b538-78cc-4a26-be68-475e46ac458b-3343371

Thanks :slight_smile:

Hi Pie :slight_smile: Did you have a chance to check my site?

Hey there! I did indeed. Unfortunately, the redirect rule works for me.

Using a VPN, from Madrid, if I request /angstpatienten from that deploy URL, I am directed to the .es domain. This is true in both Safari and Chrome, with or without the cache.

This is also true for the FR redirect, which redirects me to the .fr domain accurately when I appear in Paris.

If this is still an issue, can you provide me with a x-nf-request-id for a request to the /angstpatienten page when it doesn’t redirect?

It does redirect indeed. But the SEO crawlers return 404 and zero redirects :thinking:
Does it look like the redirect is happening too late for google?

That’ll be a question for Google, I’m afraid. It depends what you’re trying to cache, or requesting to be crawled. You could ask them to try again, or specify specific URLs: Ask Google to recrawl your URLs  |  Google Search Central

If you’re trying to crawl the deploy preview itself, that’s prevented by our introduction of canonical headers: Improved SEO with canonical link headers

Thanks for insights! I will take a look at the materials you sent :wink: