3

mage 2.1.7 "use Store code in URL" set to YES.

Have 3 stores, one for our default/original store at "/" with code "France" and one for our south Korea and north Korea stores.

The default store is currently accessible on "/" and "/france" and the other 2 stores on "/south-korea" and "/north-korea" - that's fine. But the default store should only be accessible on "/"

We can use Nginx to rewrite the URL "/france" to "/" but the URLs generated by magento2 include the store code. Where do I override this behavior? thank you.

2 Answers 2

0

Instead of adding the store code via the Magento setting why not just add the store codes for south Korea and north Korea via Nginx rewrite rule that would alleviate your '/' issue at the very least. Then just set your base URLs with the store codes in them.

-1

Preference \Magento\Store\Model\Store, override the following protected function.

protected function _updatePathUseStoreView($url)
{
    if ($this->isUseStoreInUrl()) {
        $url .= $this->getCode() . '/';
    }
    return $url;
}

with below code:

protected function _updatePathUseStoreView($url)
{
    if ($this->isUseStoreInUrl()) {
        if($this->getCode() == 'default'){
            $url .= '/';
        }else{
            $url .= $this->getCode() . '/';
        }

    }
    return $url;
}
1
  • Doesnt work with store switcher (the store code is pre-pended again)
    – George
    Commented Dec 14, 2017 at 15:16

Your Answer

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

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