How to rewrite root path to /[locale] path in next 13 with app dir?
Unanswered
Isac Paz posted this in #help-forum
Isac PazOP
I'm trying to show the index page of my website in the default language pt-BR, so when user access that page the url will be '/', but the [lang]/pt-BR will be render.
I try this:
I try this:
const nextConfig = nextTranslate({
async rewrites() {
return [
{
source: '/',
destination: '/pt-BR',
},
]
},
});
module.exports = nextConfig;7 Replies
You want to hide the locale in the url, correct?
For example rewrite
/pt-BR/about to /about?Note that if you followed the i18n example given in Next.js' repo, all pages (including the root page) will be prefixed with the locale.
@not-milo.tsx For example rewrite `/pt-BR/about` to `/about`?
Isac PazOP
Yes, this is I want
Actually my structure is it:
the translations are working correctly, but always with the prefix in the url. I don't need to hide all prefixes, just pt-BR. I'd like to leave pt-BR as the default and omit it.
You have to check if the default locale is in the request pathname, and if it's there rewrite the request to a url without the locale.
You can find an example here: https://github.com/milovangudelj/milovangudelj.com/blob/master/middleware.ts#L45-L64
You can find an example here: https://github.com/milovangudelj/milovangudelj.com/blob/master/middleware.ts#L45-L64