0

I would like to have different URL keys for a category for every store view. ex http://store.com/electronics.html for EN store

http://store.com/electronics-gr.html for a GR view.

When i switch store views when inside the category it properly redirects me to the correct one. If however i have my website on the GR store view and i click a link outside of my shop http://store.com/electronics.html that will throw a 404 not found.

Only solution i could come up with was each time a category is saved to create a 301 Redirect for say /electronics.html to /electronics-gr.html for the GR store view and so on.

Before going on through i would like some feedback, if there is some other solution i could go with?

4

2 Answers 2

1

https://pastebin.com/2DfYkUEj

Came up with this. The const are just a temp solution but it looks ok.

0

Yes, i also faced this issue Above (Magento 2.2.3) Version while using Language Switcher.

Please follow below code to resolved this issue of redirection while changing language switcher :

  • First of all override the file 'vendor/magento/module-url-rewrite/Model/StoreSwitcher/RewriteUrl.php' and Replace below code.

From line No. 67 to 77

if ($oldRewrite) {
            // look for url rewrite match on the target store
            $currentRewrite = $this->urlFinder->findOneByData([
                UrlRewrite::REQUEST_PATH => $urlPath,
                UrlRewrite::STORE_ID => $targetStore->getId(),
            ]);
            if (null === $currentRewrite) {
                /** @var \Magento\Framework\App\Response\Http $response */
                $targetUrl = $targetStore->getBaseUrl();
            }
        }

To

 if ($oldRewrite) {

        $currentRewrites = $this->urlFinder->findAllByData([
            UrlRewrite::TARGET_PATH => $oldRewrite->getTargetPath(),
            UrlRewrite::STORE_ID => $targetStore->getId(),
        ]);

        if (null === $currentRewrites || empty($currentRewrites)) {
            /** @var \Magento\Framework\App\Response\Http $response */
            $targetUrl = $targetStore->getBaseUrl();
        } else {
            foreach($currentRewrites as $rewrite) {
                $targetUrl = $targetStore->getBaseUrl() . $rewrite->getRequestPath();
                break;
            }
        }
    }

I Hope this is Helpful to You.

Thanks.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.