['nuxt-i18n', {
parsePages: false,
locales: ['es'],
strategy: 'prefix',
detectBrowserLanguage: {
useCookie: true,
cookieKey: 'i18n_redirected',
alwaysRedirect: true,
fallbackLocale: 'es'
},
vueI18n:聽{
messages: {
'es': require('./locales/es.json')
}
}
}],
Here is my nuxt-i18n configuration.
Redirect to /es as it is the only one available language.
Google Search Console is telling me that I have an ERROR 404 in / when crawling data from my website

I have no problem entering the webpage, but my website is not being indexed by Google on their Search Engine because of this.
There is no strategy called prefix. That might be your problem.
Otherwise, maybe you should consider using no_prefix strategy since you only have one locale?
Hello @rchl
https://nuxt-community.github.io/nuxt-i18n/routing.html#prefix
If this is not outdated, prefix is an strategy.
"With this strategy, all routes will have a locale prefix."
Also, I want it to be /es for the future, so I don't have to change all url in the future for SEO purposes.
Thanks.
Ok for now as this is not working properly (don't know if it is my fault) and I need to get a solution right now, I am gonna follow your suggestion as there is an strategy called prefix_except_default so in the future, I can keep all the urls with the same / path and also add /en later.
Thanks, I am gonna close this, If anyone is getting the same problem, be free to open it again so they can take a look at this problem.
You're right. I'll have a look at what might be a problem with prefix strategy.
Well, I have same issue. I use the prefix strategy for better SEO. If I acces to http://myapp.test/ it fails, I need to specify the locale even I have configured fallbackLocale option.
If I acces to http://myapp.test/ca/ or http://myapp.test/es/ It works as expected.
Sorry, I can't reproduce that. I've created codesandbox with basic "prefix" configuration at https://codesandbox.io/s/nuxt-i18n-strategy-prefix-5860y
Going to the root URL, without locale prefix, works for me whether cookie is set or not (in incognito mode).
If you have some more information on how to reproduce then please post here.
Sorry to answer so late.
Well, I have reproduced my configuration in this codesandbox: https://codesandbox.io/s/nuxt-i18n-strategy-prefix-0yhex
If you clear your cookies and go to the repo URL in codesandbox browser, you will get:
This page could not be found
Back to the home page
If you to to https://0yhex.sse.codesandbox.io/ca or https://0yhex.sse.codesandbox.io/es, it will print the correct message and will set a cookie, then it will automatically redirect from now on.
Thanks rchl!
Thanks a lot. I can see the problem now and will look into it.
I really wanted to fix it but the more I've looked, I've realized that fixing this would basically make any page redirect which means it would be impossible to get 404 response for any URL. That's not good for SEO.
There is rootRedirect option though, and when set to ca, it pretty much will do what you want. Can you check that out?
Well, with rootRedirect it redirects to /ca and the message prints as expected. But it will redirect always to the same language.
I think that the trick will be that you can get the browser language and then set the rootRedirect option. Do you think that it can be implemented?
Maybe you can add a autoDetectRootRedirect option and set it as:
// Handle auto detect root path redirect
if (route.path === '/' && autoDetectRootRedirect) {
let lang = navigator.language
// Then, you can check if language is in locales.
// Finally, redirect to browser's language
redirect('/' + lang, route.query)
return
}
// Then, original rootRedirect code:
// Handle root path redirect
if (route.path === '/' && rootRedirect) {
redirect('/' + rootRedirect, route.query)
return
}
I don't want to add new options unless absolutely necessary. There are so many right now, it's close to impossible to think of all permutations and feel safe while making a change (there are tests but those don't cover all cases either since there are so many variants...).
Unfortunately, I'm short on time right now and I can't think of a quick and safe solution. Also, there are many things to consider with changing that. For example, should behavior depend on alwaysRedirect or should work irrespective of it? Should it depend on rootRedirect? Or even more generally, what should happen when detectBrowserLanguage is disabled? Should it still redirect to default locale (if set) or not. Thinking about those (and there are more options that could affect that), makes my head hurt...
Ok, I understand you. But, how this issue can be solved? Maybe if rootRedirect is equal to auto it will be redirected to browser language? I don't know.
Any solutions to fix this? Or updates?
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
Sorry, I don't have time right now to figure out how to fix it. Especially as it's unclear what the fix would have to be (if you consider all the cases).
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
This specific case (configuration posted in the initial comment) appears to have been fixed by #510.
Most helpful comment
This specific case (configuration posted in the initial comment) appears to have been fixed by #510.