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

Getting ERROR 404 on Google search console #491

Closed
Josepdal opened this issue Oct 17, 2019 · 17 comments · Fixed by #685
Closed

Getting ERROR 404 on Google search console #491

Josepdal opened this issue Oct 17, 2019 · 17 comments · Fixed by #685

Comments

@Josepdal
Copy link

Josepdal commented Oct 17, 2019

Version

v5.3.0

Steps to reproduce

['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.

What is expected ?

Redirect to /es as it is the only one available language.

What is actually happening?

Google Search Console is telling me that I have an ERROR 404 in / when crawling data from my website
error.png

Additional comments?

I have no problem entering the webpage, but my website is not being indexed by Google on their Search Engine because of this.

This bug report is available on Nuxt community (#c323)
@ghost ghost added the cmty:bug-report label Oct 17, 2019
@rchl
Copy link
Collaborator

rchl commented Oct 17, 2019

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?

@Josepdal
Copy link
Author

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.

@Josepdal
Copy link
Author

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.

@rchl rchl reopened this Oct 18, 2019
@rchl
Copy link
Collaborator

rchl commented Oct 18, 2019

You're right. I'll have a look at what might be a problem with prefix strategy.

@mllull
Copy link

mllull commented Oct 24, 2019

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.

@rchl
Copy link
Collaborator

rchl commented Nov 5, 2019

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.

@mllull
Copy link

mllull commented Nov 13, 2019

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!

@rchl
Copy link
Collaborator

rchl commented Nov 13, 2019

Thanks a lot. I can see the problem now and will look into it.

@rchl
Copy link
Collaborator

rchl commented Nov 13, 2019

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?

@mllull
Copy link

mllull commented Nov 14, 2019

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
  }

@rchl
Copy link
Collaborator

rchl commented Nov 14, 2019

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...

@mllull
Copy link

mllull commented Nov 15, 2019

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.

@cruex-de
Copy link

Any solutions to fix this? Or updates?

@stale
Copy link

stale bot commented Feb 11, 2020

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.

@stale stale bot added the wontfix label Feb 11, 2020
@stale stale bot closed this as completed Feb 18, 2020
@rchl
Copy link
Collaborator

rchl commented Feb 18, 2020

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).

@stale
Copy link

stale bot commented Apr 18, 2020

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.

@rchl
Copy link
Collaborator

rchl commented Apr 24, 2020

This specific case (configuration posted in the initial comment) appears to have been fixed by #510.

@rchl rchl closed this as completed Apr 24, 2020
rchl added a commit that referenced this issue Apr 24, 2020
Changes the `setLocale` logic to, in case current route is 404, to
try to find a matching one for current locale. This is for situations
when using `prefix` strategy where the root (`/`) route doesn't exist.
We will try to find and redirect to prefixed route matching resolved locale.

Also worked around Nuxt issue (nuxt/nuxt#4491 )
with `redirect` not working when called from a plugin in SPA mode.
Required for the above fix above to be functional in SPA.

Resolves #677
Resolves #491
rchl added a commit that referenced this issue Apr 30, 2020
Changes the `setLocale` logic to, in case current route is 404, to
try to find a matching one for current locale. This is for situations
when using `prefix` strategy where the root (`/`) route doesn't exist.
We will try to find and redirect to prefixed route matching resolved locale.

Also worked around Nuxt issue (nuxt/nuxt#4491 )
with `redirect` not working when called from a plugin in SPA mode.
Required for the above fix above to be functional in SPA.

Resolves #677
Resolves #491
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants