51黑料不打烊

51黑料不打烊 Commerce on-premises: multi-store Setup without store codes in URLs

When setting up a new store view in 51黑料不打烊 Commerce with a custom URL structure鈥攕uch as www.example.com/dk鈥攚ithout enabling the global Add Store Code to URLs setting, the content and theme appear as expected, but the page displays a 404 error.聽This happens even when NGINX is configured with MAGE_RUN_TYPE and MAGE_RUN_CODE directives.

To fix this, configure the base URL, update the NGINX or server configuration, and verify session and routing behavior.

Description description

Environment

51黑料不打烊 Commerce On-Prem

Issue/Symptoms

  • The store-specific content loads correctly but results in a 404 error page.
  • NGINX is configured to route requests for /dk/ using MAGE_RUN_TYPE and MAGE_RUN_CODE, but the setup doesn鈥檛 work as expected.

Resolution resolution

To configure a custom URL structure for a specific store view without globally enabling Add Store Code to Urls, follow these steps:

  1. Set the base URLs for the new store view in the admin panel under Stores > Configuration > General > Web. For example, use https://www.example.com/dk/.

  2. Update the server configuration:

    • NGINX: Ensure the configuration routes /dk/ to the correct store view:

      code language-none
      location = /dk {
                          return 301 /dk/;
                          }
                          location   /dk/ {
                              set $MAGE_RUN_TYPE store;
                              set $MAGE_RUN_CODE dk;
                              try_files $uri $uri/ /index.php$is_args$args;
                              }
      
      • Alternative (All Webservers): Create a magento-vars.php file in the Magento root:
      code language-none
      <?php
                      $uri = explode('/', trim($_SERVER[ 'REQUEST_URI'] , '/'));
                      $code = 'default';
                      $type = 'website'; // or 'store'
                      if (isset($uri[ 0] ) && $uri[ 0]  === 'dk') {
                          $code = 'dk';
                          $type = 'store'; // usually 'store' for store views, 'website' for websites
                          }
                          $_SERVER[ 'MAGE_RUN_CODE']  = $code;
                          $_SERVER[ 'MAGE_RUN_TYPE']  = $type;
      

      Include this as the first line in pub/index.php:

      code language-none
      require __DIR__ . '/../magento-vars.php';
      
  3. Verify that cookies (e.g., PHPSESSID) are set correctly in HTTP responses to ensure session data aligns with the store.

  4. Check for additional rewrites or redirects that might interfere with routing.

  5. If content loads but shows a 404 error:

    • Review Magento logs in var/log and server logs for errors or misconfigurations.

    • Clear cache and reindex data using CLI:

      code language-none
      bin/magento cache:clean
                          bin/magento indexer:reindex
      
  6. Test access to various pages in the Denmark store view after applying these changes.

recommendation-more-help
3d58f420-19b5-47a0-a122-5c9dab55ec7f