Magento Language Switcher Gives 404 Error - Fix

If your Magento returns 404 after switching language on product pages, categories or CMS pages, you've landed in the right place. We'll provide an ultimate solution that will help you to fix and avoid this issue in the future. 

But first, let's figure out why this issue appears.

Why Language Switcher Gives 404 Error?

When you manage a multi-language Magento store, chances are you'll face the 404 error after switching languages on your store pages. Besides, it is also commonly marked in Google Search Console issues. It usually happens because you're missing one tiny thing — hreflang tags. 

Hreflang tags are small snippets of HTML code that let search engines know that you have different alternatives to the same page. In other words, these tags are used to "link" pages in different languages for better store switching and customer experience.

Besides, adding hreflang tags helps Google to pull out different pages for localized search results.

Hreflang Tags in Magento 2 Category Page

How to Fix 404 Error After Switching Store View?

As you might have already guessed, to solve the language switcher 404 error you need to add hreflang tags to your store pages. 

Add Hreflang Tags Manually

While it is not impossible, adding these tags by hand for each page would take tons of time. However, if you're still determined to do it yourself, here are the options.

1. You can add hreflang tags in the <head> tags for each page on your store.

Hreflang Tags in Head Tag

2. You can add hreflang tags through the sitemap.xml file. For that, you need to create separate <url> elements for each alternative page. 

Hreflang Tags in Sitemap

Still, these task is not impossible. But if you don't want to spend hours setting this up, you need a quicker solution.

Add Hreflang Tags Automatically

If you're not good with code, or simply want to solve the language switcher 404 error faster, you need the Magento Hreflang Tags Extension.

It enables you to add hreflang tags to your products and categories automatically (given that products on different store views have the same ID).

However, there is also an option to set hreflang tags for various pages from the admin panel. You don't have to deal with code. Simply define alternative pages in the admin.

Hreflang Tags for Homepage in Magento 2

The process comes down to a few clicks, and the hreflang tags are added to the page source code. 

Alternate Tags for Homepage Magento

Just like that. You've fixed the language switcher 404 error and improved your ranking in Google.

Sound too easy? It's because it is super easy with this handy Hreflang Tags tool. The settings for each page are quite similar. However, you should start with the basic hreflang tags configuration.