0

Has anyone successfully got multiple stores/storeviews running on Magento 2.3 using the URI as an identifier?

EG https://www.example.com/ = default store/view

https://www.example.com/store2/ = second store/view

I have the essentials sorted, but the additional element in the uri appears to be interfering with the normal workings of Magento, resulting on constant 404 pages.

This is presumably because the standard convention is module/controller/action for URIs in Magento, so this setup is essentially looking for the "store2" module.

I have considered using the "add storeview to url" option, but this would result in the default being "www.example.com/default/", which the client does not want. Logical (and typically documented) way to solve this would be to use a subdomain, but the client does not want to use "store2.example.com" format, insisting on the "www.example.com/store2/".

Any thoughts anyone?

Thanks

0

Something like this

https://magento.stackexchange.com/a/183980/70343

Although a note. You want your longer url first.

So that means your bases url for store2 and first entry in index.php will be this https://www.example.com/store2/

Alsp you might have to preg_match on one or more $_SERVER superglobals to catch that any url has /store2/ part

0

This scenario can be used for different language versions.

store.com -- default

store.com/store2 --- second store (or for example /de for german version)

  1. Create new website or store in backend - with all settings around.

In my scenario I created website => store=> store view because I want separate clients, prices etc.

  1. Stores=> Configuration => General => Web => Change SCOPE in top, to Your website or store.

Edit all secure and not secure:

Base URL - domain/store2/

Base Link URL - domain/store2/

Base URL for Static View Files - here I point to default store (its up to You)

Base URL for User Media Files - same - if you want use different media files You need recreate it on your directory.

  1. create directory in magento root - store2/
  2. copy .htaccess and index.php to store2/
  3. replace all content of store2/index.php to:

// your_website - change this with the code that you use for website or store in backend

// website - change to store or website (there is no store view option here)

    <?php 
    require realpath(__DIR__) . '/../app/bootstrap.php';
    $params = $_SERVER;
    $params[\Magento\Store\Model\StoreManager::PARAM_RUN_CODE] = 'your_website'; 
    $params[\Magento\Store\Model\StoreManager::PARAM_RUN_TYPE] = 'website'; 
    $bootstrap = \Magento\Framework\App\Bootstrap::create(BP, $params);
    $app = $bootstrap->createApplication('Magento\Framework\App\Http');
    $bootstrap->run($app);
  1. In this point after all deployments task, etc , store should work but for later You need :

Set theme, apply, categories , products, pages ,etc

If You want different prices for websites, go to:

Catalog=> Catalog =>Price=> Scope change to website (so different prices can be only on different website level not stores)

Notes:

If you using pub/ like your target directory:

create pub/store2 and change in index.php path to bootstrap, jus add /..

/../../app/bootstrap.php

Cons of this solution:

  • after magento update, your store2/.htaccess and index.php are not updated.
  • Thanks for the thorough response. I did try a method very similar but found it didn't work, might be I missed something. However, for my own (or anyone else's) future benefit when trying this method, do you know the config example for Nginx? Since .htaccess is not read by Nginx. – user3867548 Jul 12 at 16:14
  • This method is for apache2, but its works also without .htaccess files inside directory. I know because first time I forget to copy .htaccess. Please try step by step and let me know what issues do You have. – BartZalas Jul 12 at 19:48
  • Probably also You use pub/ directory in default with nginx, so read my comment at the end of answer – BartZalas Jul 12 at 22:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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