I'm currently running Magento 2.2.1 and want to create links to a specific store view.

Each store view is translated to a certain language, and I'd like that links placed on blogs written in that language go directly to the respective store view.

I've tried adding the __store=pt query parameter but in Magento 2 this doesn't seem to work. Apparently the store switcher uses a POST call, which I can't do if I'm linking from another site.

Is there something else I can do?

2 Answers 2


I finally worked this out. It certainly is more complex than it should be but it works.

The problem is that passing the "__store" query param isn't enough for Magento to send the store cookie back. So I do it myself via rewrites.

Instead of using links of the form http://example.com/some/magento/path/?__store=pt I use http://example.com/pt/some/magento/path/.

Then I have an Apache Rewrite rule to redirect to the correct URL (without the pt in the path): http://example.com/some/magento/path/ and send the cookie back.

Here's what that rewrite looks like:

RewriteCond %{HTTPS} =on
RewriteRule ^(.*)$ - [env=proto:https]
RewriteCond %{HTTPS} !=on
RewriteRule ^(.*)$ - [env=proto:http]

RewriteRule ^/pt/(.*) %{ENV:proto}://%{HTTP_HOST}/$1?__store=pt [R,L,QSA,CO=store:pt:;:60:/:HttpOnly]

There are two types of things in magento

  1. Store
  2. Store View

If you want to create the link of the Store then you need to follow these points:-

  • a) First you need to create the folder on the root with the same name where your want to redirect. For example :


and storeName is your folder name

  • b) Then you need to create the file index.php and .htaccess under that folder. .htaccess is files is the same file which is on your root, you just need to copy that file and place them under this folder.
  • c) In the index.php file, you need to add this code

 * Application entry point
 * Example - run a particular store or website:
 * --------------------------------------------
 * require _DIR_ . '/app/bootstrap.php';
 * $params = $_SERVER;
 * $params[\Magento\Store\Model\StoreManager::PARAM_RUN_CODE] = 'website2';
 * $params[\Magento\Store\Model\StoreManager::PARAM_RUN_TYPE] = 'website';
 * $bootstrap = \Magento\Framework\App\Bootstrap::create(BP, $params);
 * \/* @var \Magento\Framework\App\Http $app \/
 * $app = $bootstrap->createApplication('Magento\Framework\App\Http');
 * $bootstrap->run($app);
 * --------------------------------------------
 * Copyright © 2013-2017 Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.

try {
    require _DIR_ . '/../../app/bootstrap.php';
} catch (\Exception $e) {
    echo <<<HTML
<div style="font:12px/1.35em arial, helvetica, sans-serif;">
    <div style="margin:0 0 25px 0; border-bottom:1px solid #ccc;">
        <h3 style="margin:0;font-size:1.7em;font-weight:normal;text-transform:none;text-align:left;color:#2f2f2f;">
        Autoload error</h3>

$params = $_SERVER;

 $params[\Magento\Store\Model\StoreManager::PARAM_RUN_CODE] = 'YOUR STORE CODE'; //Webite code as same in admin panel

 $params[\Magento\Store\Model\StoreManager::PARAM_RUN_TYPE] = 'store';

 $bootstrap = \Magento\Framework\App\Bootstrap::create(BP, $params);

 /* @var \Magento\Framework\App\Http $app /

 $app = $bootstrap->createApplication('Magento\Framework\App\Http');



  • d) Then you need to create symlink of pub/var/lib folder under this folder.
  • e) Then last you need to add the URL through admin Choose your store -> Web -> base urls like


which you created on root


If you want to do via Store View then you need to follow this approach.

a) This is only used if you want to change the language only. b) Then you need to change the one setting through the admin

Choose your store -> Configuration-> General -> Local option -> Choose your language via local option

But make sure, after implement any step please flush the cache.

Please let me know if I was able to answer your questions.

  • I'm just using store views for each language. I believe that you're explaining me how to choose a different locale per store view, correct? I've already done that.
    – pfandrade
    Commented Nov 10, 2017 at 11:26

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.