Is your feature request related to a problem? Please describe.
This scenario can seem a bit weird, but actually it's not.
The no-cookie environment can be crawling bots, social embeds etc that are using fetch/curl to get the raw html.
The issue is that when using rewriteDefault the following happen:
(Here the default locale is 'fr', the locales are fr and en)
Goes to /en
Middleware check the locale in cookies -> Nothing -> Fallback to fr.
The locale (en) is in the prefix, it's not the default locale (fr) and it's not the one stored in the cookies (fallback to fr) so we are redirected to /.
Then we add the locale to the response (in cookies). But our environment does not support cookies
Redirected to /.
Same here, the middleware check the cookies and found nothing, so if fallback to fr.
We no longer have the locale in prefix, the default locale (fr) is the same as the one in cookie (fallback to fr), so it stops early.
In conclusion we were going for /en but the response body is in french.
I also think this is a bug as rewriteDefault should only redirect if it's the default language ? In our case if we go to /en there should not be any redirection.
curl -sL http://localhost:3000/en
You should see something like <p>Current locale: <!-- -->fr</p> in it
Describe the solution you'd like
In a cookie disabled environment the rewriteDefault should work or should default to a working alternative.
Describe alternatives you've considered
Not using rewriteDefault or rewrite but that's not what we want.
Note: redirect is the only one working.
But as an idea, maybe default to the redirect behaviour if cookies are not available. (maybe based on the useragent as the issue is mostly for crawler and bots?)
Is your feature request related to a problem? Please describe.
This scenario can seem a bit weird, but actually it's not. The no-cookie environment can be crawling bots, social embeds etc that are using fetch/curl to get the raw html.
The issue is that when using
rewriteDefault
the following happen: (Here the default locale is 'fr', the locales arefr
anden
)/en
Middleware check the locale in cookies -> Nothing -> Fallback to
fr
. The locale (en) is in the prefix, it's not the default locale (fr) and it's not the one stored in the cookies (fallback to fr) so we are redirected to/
. Then we add the locale to the response (in cookies). But our environment does not support cookies/
.Same here, the middleware check the cookies and found nothing, so if fallback to
fr
. We no longer have the locale in prefix, the default locale (fr) is the same as the one in cookie (fallback to fr), so it stops early.In conclusion we were going for
/en
but the response body is in french.I also think this is a bug as
rewriteDefault
should only redirect if it's the default language ? In our case if we go to/en
there should not be any redirection.Reproduction
You can use this reproduction: https://github.com/Vahor/next-international-rewritedefault-issue In one terminal
pnpm install
pnpm dev
In another terminal
curl -sL http://localhost:3000/en
You should see something like<p>Current locale: <!-- -->fr</p>
in itDescribe the solution you'd like
In a cookie disabled environment the
rewriteDefault
should work or should default to a working alternative.Describe alternatives you've considered Not using
rewriteDefault
orrewrite
but that's not what we want.Note:
redirect
is the only one working.But as an idea, maybe default to the
redirect
behaviour if cookies are not available. (maybe based on the useragent as the issue is mostly for crawler and bots?)