With Astro I’m building the english version in /dist/en/ directory.
My netlify.toml config file:
[build.environment]
# bypass npm auto install
NPM_FLAGS = "--version"
NODE_VERSION = "20"
[build]
publish = "dist"
command = "npx pnpm i --store=node_modules/.pnpm-store && npx pnpm run build"
[[redirects]]
from = "https://polo6r.pl/*"
to = "/index.html"
status = 200
[[redirects]]
from = "https://polo6r.net/*"
to = "/en/index.html"
status = 200
[[redirects]]
from = "/*"
to = "/index.html"
status = 200
conditions = {Language = ["pl"]}
[[redirects]]
from = "/*"
to = "/en/index.html"
status = 200
conditions = {Language = ["en"]}
[[headers]]
for = "/manifest.webmanifest"
[headers.values]
Content-Type = "application/manifest+json"
[context.production.environment]
LANG = "pl"
SITE_PL_URL = "https://polo6r.pl"
SITE_EN_URL = "https://polo6r.net"
I also added another domain/alias, but when I go to https://polo6r.net I still have the Polish version of the site.
Is what I want to do even possible?
Unfortunately, I could not find any example with a similar configuration.
@spokospace I can’t advise precisely what’s occuring for you, as there seem to be a few things in the mix (cloudflare, astro, redirects, a service worker), but one thing I’ve noticed is…
If I visit the root of:
https://polo6r.net
It’s in Polish.
But if I visit any sub URL at all:
https://polo6r.net/a
It’s in English.
I’m wondering if it’s because all of the rewrites are specified with the wildcard *
You could try specifying some for the root URL (without the wildcard) higher than the wildcard rules.
In your example, I think this configuration works (conditions + language from browser):
[[redirects]]
from = "/*"
to = "/index.html"
status = 200
conditions = {Language = ["pl"]}
[[redirects]]
from = "/*"
to = "/en/index.html"
status = 200
conditions = {Language = ["en"]}
When it comes to domain configurations in netlify I am a novice, about what I currently have:
[[redirects]]
from = "https://polo6r.pl/*"
to = "/index.html"
status = 200
[[redirects]]
from = "https://polo6r.net/*"
to = "/en/index.html"
status = 200
You could try:
[[redirects]]
from = "https://polo6r.pl"
to = "/index.html"
status = 200
[[redirects]]
from = "https://polo6r.pl/*"
to = "/index.html"
status = 200
[[redirects]]
from = "https://polo6r.net"
to = "/en/index.html"
status = 200
[[redirects]]
from = "https://polo6r.net/*"
to = "/en/index.html"
status = 200
Just on the chance that having the /* doesn’t also target /