Magento 2 switching store view (language) URL does not redirect correctly
Quick background (cause maybe is related to my problem):
We migrated Magento 1.9 to Magento 2.4.4. After migrations we had to regenerate URL rewrites with the help of the module Elgentos_RegenerateCatalogUrls.
We had some minor issues with product URL KEYs which we located with the help of this module Baldwin_UrlDataIntegrityChecker and then fixed manually in the database.
Now Magento 2 is up and running. The problem is that the webstore does not redirect correctly if I switch store view (language).
For example:
(How it should work correctly)
mystore.eu/category-english/ should redirect to mystore.it/category-italian/
instead, Magento2 redirects like this (not correct redirections)
mystore.eu/category-english/ —> mystore.it/category-english/?___store=it&___from_store=en
The store redirects to the correct domain (.it), but the url key of the category (for italian store view) remains from the eu website. Also Magento adds ?___store=it&___from_store=en (but from what I understand this is the default behaviour).
I have different store views on different domains (as you can see from the example above).
I double checked the URLKEY for the category for each store view –> it is correctly set.
I reindexed and cleared cache multiple times …
I also tried this settings -> Go to Stores -> Configuration and then General -> Web as noted in this post: Store switcher url is not redirecting to the store
IMPORTANT! I tested multiple categories and redirections from/to are NOT working correctly. But for SOME product URL the redirects correctly.
I believe that the Magento 2 URL REDIRECTIONS from/to store view are actually inside URL REWRITES data base table, but for some reason the regeneration process did not created the entries in the data base.
This hypothesis comes from this post (that is similar problem): Different category URLs for store views, redirect to proper one
In one repsond there is a proposed solution to modify:
vendor/magento/module-url-rewrite/Model/StoreSwitcher/RewriteUrl.php
(from the code I assume that URL rewrites handle store view redirections).
So my questions are:
- Does any body has a problem that switching store view in Magento 2 does not redirect URL correctly?
And - Do I assume correctly that URL rewrites from/to webstore handled by Magento URL REWRITES (entries in the database); and if so how can I rebuild these entries?
Thank you.