3

I am trying to create a multistore in Magento 2. The base url is something like http://example.com/business/. Now the multi store url needs to be like http://example.com/business/fr/.

I have followed everything like that mentioned in this: http://docs.magento.com/m2/2.1/ee/user_guide/stores/stores-all-create-store.html

Created store view and assigned url in web for that. But its giving 404 error whilst checking.

After digging on web, found that we need to modify index.php like below:

switch($_SERVER['HTTP_HOST']) {

    case 'example.com/business':        
         $params[\Magento\Store\Model\StoreManager::PARAM_RUN_CODE] = 'default';
                     $params[\Magento\Store\Model\StoreManager::PARAM_RUN_TYPE] = 'store';
    break;


    case 'example.com/business/fr':        
         $params[\Magento\Store\Model\StoreManager::PARAM_RUN_CODE] = 'fr';
                     $params[\Magento\Store\Model\StoreManager::PARAM_RUN_TYPE] = 'store';
    break;
}
$bootstrap = \Magento\Framework\App\Bootstrap::create(BP, $params);
/** @var \Magento\Framework\App\Http $app */
$app = $bootstrap->createApplication('Magento\Framework\App\Http');
$bootstrap->run($app);

Still i am getting 404. Can you just point me whats i am doing wrong here. Any kind of help will be much appreciated. Thanks in adv.

4
  • There is not much tuts explaining how we can setup url like this. @Teja can you pls help me? Commented Nov 18, 2017 at 15:39
  • 1
    Dont modify index.php file or .htaccess file. Just enable web server urls for all store views and upload .htaccess into root. Then it will clear Commented Nov 20, 2017 at 4:52
  • @ShyamKrishnaSreekumar Did you create multi store?
    – zus
    Commented Jan 3, 2019 at 10:54
  • yes ofcourse i did. I managed to create multiwebsite. Commented Jan 9, 2019 at 11:44

2 Answers 2

3

There are 2 solution for that you can follow which one liked to use :-

First Option

System -> Configuration -> Web -> Url Options -> Add Store Code to Urls

Set Yes to this options, your store code will automatically append on store switch, flush caches. This solution credit goes to @Priyank

Second Option

1) Create store view.

2) select France store from admin panel and change base url, base link url, Secure base url, Secure base link url from admin panel (Stores -> Configuration -> General -> Web) :

http://example.com/business/fr/

3) Create folder in root directory with name fr

4) Copy htaccess & index.php from root

5) Replace index.php code following code

$bootstrap = \Magento\Framework\App\Bootstrap::create(BP, $_SERVER);
 /** @var \Magento\Framework\App\Http $app */
$app = $bootstrap->createApplication('Magento\Framework\App\Http');
$bootstrap->run($app);

With Below code

$params = $_SERVER;
$params[\Magento\Store\Model\StoreManager::PARAM_RUN_CODE] = 'fr'; 

//store 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');
$bootstrap->run($app);

6) Create symlinks

ln -s /var/www/html/http://example.com/business/app/ app 
ln -s /var/www/html/http://example.com/business/lib/ lib 
ln -s /var/www/html/http://example.com/business/pub/ pub 
ln -s /var/www/html/http://example.com/business/var/ var 

Here /var/www/html/http://example.com/business/ is path of your project to root directory change as per your own configuration.

Don't forgot flush cache.

3
  • thank you, will try this and let you know. I have done the first option yesterday itself and is working fine. Let me try the second method also. Commented Nov 20, 2017 at 15:01
  • I followed the second method, I've done all the mentioned changes except symlinks, can you explain where I've to set the symlinks.
    – senthil
    Commented Apr 4, 2019 at 6:27
  • You need to create symlinks into a folder of which you have created in project root directory for the second website Commented Apr 4, 2019 at 6:38
0

My solution of choice is not to modify index.php. Most because I like to keep Magento the way it is. I don't think you need to ship the default parameters (i.e. case default).

This is how my index.php looks like default (below the try and catch-clauses):

$bootstrap = \Magento\Framework\App\Bootstrap::create(BP, $_SERVER);
/** @var \Magento\Framework\App\Http $app */
$app = $bootstrap->createApplication(\Magento\Framework\App\Http::class);
$bootstrap->run($app);

Within htaccess (in my installation, it is htaccess.conf, in others, it coul well be .htaccess), I provide the right variable to Magento:

SetEnvIf Host www\.example\.com/business/fr MAGE_RUN_CODE=fr
SetEnvIf Host www\.example\.com/business/fr MAGE_RUN_TYPE=store
SetEnvIf Host ^example\.com/business/fr MAGE_RUN_CODE=fr
SetEnvIf Host ^example\.com/business/fr MAGE_RUN_TYPE=store

This works perfect for me.

3
  • no, still it gives 404. And i think htaccess wont allow to amend /fr like. I think so. Commented Nov 18, 2017 at 12:13
  • Have you restarted the web server? Above htaccess is applicable for Apache. Shouldn't have said it worked perfect. The similar setup but with different domains works perfect for me. I'll try in my dev environment in a couple of hours if not resolved. Commented Nov 18, 2017 at 12:20
  • not working even after restart. :( Commented Nov 18, 2017 at 12:39

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.