Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Redirect from default language should be permanent #591

Closed
max-frai opened this issue Oct 31, 2023 · 3 comments
Closed

Redirect from default language should be permanent #591

max-frai opened this issue Oct 31, 2023 · 3 comments
Labels
bug Something isn't working unconfirmed Needs triage.

Comments

@max-frai
Copy link

Description

For seo-correctness when we want to skip default language we should do a redirect to page without mentioned page language:

site.com/en/page -> site.com/page
site.com/de/page -> site.com/de/page

return NextResponse.redirect(urlObj.toString());

In middleware redirect function you have:
return NextResponse.redirect(urlObj.toString());

It produces 307 code which is "temporarily" redirect. This is not good for seo purposes, because google crawler will follow this redirect each time and each redirect chain decrease number of requests per day allowed for a site.

Solution is:
return NextResponse.redirect(urlObj.toString(), { status: 308 });

This way google won't remember and follow redirect for default locale each time.

image

Mandatory reproduction URL (CodeSandbox or GitHub repository)

https://next-intl-example-next-13.vercel.app/en

Reproduction description

https://next-intl-example-next-13.vercel.app/en

Expected behaviour

https://next-intl-example-next-13.vercel.app/en this page should redirect to https://next-intl-example-next-13.vercel.app/ with 308 status code, not 307

@max-frai max-frai added bug Something isn't working unconfirmed Needs triage. labels Oct 31, 2023
@amannn
Copy link
Owner

amannn commented Nov 3, 2023

There's some nuance to this, as the next-intl middleware definitely needs to use temporary redirects.

I guess it's up to debate if the use case of redirecting /en to / for defaultLocale: 'en' and localePrefix: 'as-necessary' could be permanent.

Note that in the upcoming 3.0 release we're switching the default for localePrefix to always (as-necessary remains supported though). Among other topics, the question about the status code of this redirect also vanishes with localePrefix: 'always'. I'd generally recommend moving to that routing strategy.

However, let's go back to the topic:

because google crawler will follow this redirect each time

Where does the Google Crawler pick up the /en route in the first place? It's mostly there for compatibility, but / is the target of the redirect and the Link header also describes this route to be used for users that prefer the en locale:

Link: <https://next-intl-example-next-13.vercel.app/>; rel="alternate"; hreflang="en",
      <https://next-intl-example-next-13.vercel.app/de>; rel="alternate"; hreflang="de",
      <https://next-intl-example-next-13.vercel.app/>; rel="alternate"; hreflang="x-default"

E.g. when building a sitemap, you should consider linking to / instead of /en.

@amannn
Copy link
Owner

amannn commented Nov 23, 2023

Closing this due to inactivity …

@RicSala
Copy link

RicSala commented Sep 16, 2024

i agree that it should be a permanent redirect. Otherwise Google keeps going there..

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working unconfirmed Needs triage.
Projects
None yet
Development

No branches or pull requests

3 participants