Hello everyone,
I’m having some trouble setting up redirects on my Netlify site and I was hoping someone could help me out.
Here’s what I’m trying to achieve:
- When a user visits
https://customdomain.com
, I want to serve the content fromhttps://maindomain.com/custompage
without changing the URL in the browser. - For all other paths on
customdomain.com
, I want to redirect to the corresponding paths onmaindomain.com
.
To accomplish this, I added the following rules to my netlify.toml
file:
[[redirects]]
from = "https://customdomain.com"
to = "https://maindomain.com/custompage"
status = 200
force = true
This helped me when a user visits https://customdomain.com
I served the content from https://maindomain.com/custompage
without changing the URL in the browser. Perfect. However, for all other paths existing on maindomain.com
(e.g. maindomain.com/contact
), I was having them also existing under customdomain.com
(e.g. customdomain.com/contact
) and that wasn’t intended. Intention is for all paths like customdomain.com/contact
to redirect fully including url change to maindomain.com/contact
.
I then tried adding the following rules to my netlify.toml
file:
[[redirects]]
from = "https://customdomain.com"
to = "https://maindomain.com/custompage"
status = 200
force = true
[[redirects]]
from = "https://customdomain.com/*"
to = "https://maindomain.com/:splat"
status = 301
force = true
However, this configuration didn’t work as expected. The proxy redirect for https://customdomain.com
worked, but the URL in the browser changed to https://maindomain.com/custompage
. Also, the wildcard redirect didn’t seem to work at all.
I’ve also tried changing the order, but still no success:
[[redirects]]
from = "https://customdomain.com/*"
to = "https://maindomain.com/:splat"
status = 301
[[redirects]]
from = "https://customdomain.com"
to = "https://maindomain.com/custompage
status = 200
force = true
I then tried changing force = true
to force = false
in the 301 rule, like this:
[[redirects]]
from = "https://customdomain.com/*"
to = "https://maindomain.com/:splat"
status = 301
force = false
But this didn’t solve the issue either. The URL still changed when visiting https://customdomain.com
, and the wildcard redirect still didn’t work.
I’ve checked the Netlify documentation on redirects and followed the instructions there, but I’m still stuck. I’m not sure what I’m doing wrong.
Does anyone have any suggestions on how to fix this? Any help would be greatly appreciated!
Thank you in advance for your assistance.
My site is https://localization-hq.netlify.app