URL nextjs中不带区域设置的重定向



当我以这种方式重定向时:

{
source: "/restauracja",
destination: "/restaurant",
permanent: true,
},

它将我重定向到/pl/restaurant

如何在没有第二个"pl"的情况下修复它并重定向?它只在重定向时发生,正常情况下默认本地不会显示在url中。这是SEO的一个问题,因为它复制了网站。我想做从domain.pl/pl/*到domain.pl/*的301重定向的全局设置,但不知道如何做,也无法通过搜索找到解决方案。

它在next.config.js:中的外观

...
i18n: {
// These are all the locales you want to support in
// your application
locales: ["pl", "en", "de"],
localeDetection: false,
// This is the default locale you want to be used when visiting
// a non-locale prefixed path e.g. `/hello`
defaultLocale: "pl",
// This is a list of locale domains and the default locale they
// should handle (these are only required when setting up domain routing)
},
async redirects() {
return [
{
source: "/restauracja",
destination: "/restaurant",
permanent: true,
},
{
source: "/klub-pub",
destination: "/club",
permanent: true,
},
{
source: "/kawiarnia",
destination: "/cafe",
permanent: true,
}
];
},
});

谢谢你帮助

在我看来,本地化路径(如restauracja作为restaurant的翻译页(在NextJs内置i18n系统中根本不可能。

这里列出了什么是可能的,什么不是(显然(:

--- path --------- language -- possible -- remark ------------
/pl/restauracja  |    PL    |    no    | (translated path with locale, )
/restauracja     |    PL    |    no    | (translated path without locale)
/pl/restaurant   |    PL    |    yes   | (default path with locale)
/restaurant      |    EN    |    yes   | (default path without locale)
/en/restaurant   |    EN    |    yes   | (default path with locale)

我找不到任何可靠的信息(既没有如何做到这一点,也没有像"不支持本地化路径"这样的备注(,但我发现的一切似乎都不支持。

我完全禁用了内置的i18n系统,并自己实现了整个系统。

最新更新