Multiple domains redirect

Hi there.

I’ve read through some of the previously created topics here and found some guys with the same issue i’m having. This guy and this guy.
So, I have tried creating both the _redirects file, and adding the redirects to the netlify.toml file. But it just won’t redirect. Both domain1 and domain2 is up and running, but the url stays the same.

Any help will be appreciated!

Hey @Alexander,

The best source of knowledge RE: multiple domains is the Domain aliases doc.

Then, for redirects, you want to check this out. I’d personally persevere with the _redirects file; it takes precedence over the netlify.toml file and it will accomplish what we need.

What site builder are you using? Jekyll can be a little funny but that’s discussed above :point_up:.

Failing this, do you have your site name to hand?

Hi. Thx for the reply.
We are creating the page in React, bootstrapped with create-react-app.
I did try with the _redirects file as well. Added it to the public folder. No change.
The sites are playghostleague.com and ghostleague.no. Playghostleague.com is primary, and we want ghostleague.no to redirect to this one.

hey alexander, can you please post the content of your redirects file?

Hey. Ye, sure.
As of now we only use the netlify.toml file. Its contents:

[build]
  command = "yarn build"
  publish = "build"

[context.branch-deploy.environment]
  NODE_ENV = "development"
  YARN_VERSION = "1.9.4"

[context.production.environment]
  YARN_VERSION = "1.9.4"

# To make Netlify return 200 on other routes than root, since this is a client-side app
[[redirects]]
  from = "/*"
  to = "/index.html"
  status = 200

# Redirects from ghostleague.no
[[redirects]]
  from = "https://ghostleague.no"
  to = "https://playghostleague.com"
  status = 301

[[redirects]]
  from = "https://www.ghostleague.no"
  to = "https://www.playghostleague.com"
  status = 301

When i tested with the _redirects file it looked like this:

https://ghostleague.no https://playghostleague.com 301
https://www.ghostleague.no https://www.playghostleague.com 301

Hm. I can see that your deploy log sees the 3 redirects.

Could you try changing 301 to a 301! (with the exclamation) for me? Also, to keep things cleaner, I’d be inclined to make https://www.ghostleague.no redirect to https://playghostleague.com in order to avoid redirecting from www- to non-www.

Hi. Thanks for reply.
Looks like some of that did the trick! :smiley:

So final solution:
Removed the redirects from the netlify.toml file as these did not work. Added exclamation marks to the 301 and removed www from second redirect. The _redirect file is placed in the public folder. Not in root folder alongside the netlify.toml file. The placement of this file was never clear to me, so i tried both.

_redirects file:

https://ghostleague.no https://playghostleague.com 301!
https://www.ghostleague.no https://playghostleague.com 301!

Thanks for the help guys! :slight_smile:

1 Like