Skip to content

Best way to handle store switch redirects in Magento 2

Let’s assume we have the following situation: 1 Magento website with 2 stores (EN – default, IT) and 1 product.

A user is accessing the website and the default store view is loaded (EN). The user visits the product page (website.com/boat.html) and then, from the same page, he switches the store to IT. All good, the new URL is loaded (website.com/barca.html).

He shares the IT product URL with a friend (website.com/barca.html), but when the friend opens the link (having the EN store view as the default one), the search page is opened with no results instead of the EN product URL.

As a solution, we can create separate URL Rewrites for each store view: for EN website.com/barca.html => website.com/boat.html and vice-versa for the IT store view.

So, I have 2 questions related to this:

  1. Are there any other solutions to this problem? I think of intercepting the store view event and determining the correct URL based on the target store view.
  2. Are 301 Permanent redirects the correct solution, instead of having a 302 Temporary redirect, from an SEO perspective?

Thank you!