0

I have 2 stores on my Magento 2 website. one for Srilanka & the other for Australia. I am redirecting my customers based on customer's IPs to relevant sores. Whenever I am redirecting the customer to an Australian store, I am getting the URL like below

https://staging.mywebsite.lk/aus/?___from_store=default

After going through the product page and category pages URL is appearing without /?___from_store=default

I tried 302 redirects using htaccess file like below. But no luck.

Redirect 301 /aus/?___from_store=default https://staging.mywebsite.lk/aus/

This is happening only on the home page. How can I remove this from my url? please help to short this out.

1 Answer 1

0

Turn off store code urls in admin admin > stores > configuration > General > Web > Add Store Code to Urls > No run upgrade, static-content-deply and cache clean/flush commands

This comes from \Magento\Store\Model\Store::getCurrentUrl:

public function getCurrentUrl($fromStore = true) {...

If you change the default value of the variable $fromStore from true to false, the parameter won't show up any more. You can archieve that with a before plugin as follows:

public function beforeGetCurrentUrl(Store $store, $fromStore = true) { return [false]; }

2
  • i only need to remove default store code, i need to use relevent store code aus for australia
    – Mujahidh
    Apr 15, 2021 at 8:26
  • Please check the latest edit Apr 15, 2021 at 9:55

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.