Custom domain doesn't show because of stale 301 redirect

Hello,

I’ve converted my wordpress blog to gatsby which I’m hosting on netlify at ecofem.netlify.app.

I already had a domain (ecofeministmama.com) and I asked the hosting company (lowesthosting) to sort out the forwarding. They did that with the following .htaccess file:

RewriteEngine on
RewriteBase /
RewriteRule (.*) https://ecofem.netlify.app/$1 [R=301,L]

…This forwarded users ok, but it left ‘ecofem.netlify.app’ in the address bar. Lowesthosting weren’t able to offer a satisfactory solution to this.

So I did some research and have now set things up successfully by setting up the custom domain in netlify, copying across all the DNS records, and pointing the lowesthosting nameservers at the netlify ones.

So this seems to work perfectly now (i.e. type in ecofeministmama.com and you get the gatsby site and see ‘ecofeministmama.com’ in the address bar). BUT in my own browser I still see ecofem.netlify.app - I guess the 301 is cached. Of course, i can clear my browser’s cache, but the point is that any visitors who visited in that period when the 301 was in force (i.e. before I configured the netlify DNS etc.) will see ‘ecofem.netlify.app’ …forever?! (I don’t know much about redirects, but I understand you can put an expiry on 301s - unfortunately the lowesthosting person didn’t!)

This stackoverflow post mentions setting a redirect right back, in the hope (?) that a browser will see the circular redirects and invalidate their own cached redirect. But I’d greatly appreciate the insight of any netlify experts in case there is something else I can do - or indeed if they are able to confirm or deny that this redirect-back idea will work and won’t break anything else!

@getzg Welcome to the Netlify community.

Have you tried setting up a redirect instruction along these lines?

https://ecofem.netlify.app/* https://www.ecofeministmama.com/:splat 301!

2 Likes

@gregraven thank you so much! Following your suggestion it appears I have fixed it as follows (in case it helps anyone else one day…):

I set up such a redirect in my netlify.toml:

[[redirects]]
  from = "https://ecofem.netlify.app/*"
  to = "https://www.ecofeministmama.com/:splat"
  status = 301
  force = true

Got a brief error in my browser (think it was ‘too many redirects’) before it sorted itself and now it works consistently fine (no errors). I presume users with cached redirect will have the same experience.

Thanks again!

2 Likes