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/
usingMAGE_RUN_TYPE
andMAGE_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:
-
Set the base URLs for the new store view in the admin panel under Stores
>
Configuration>
General>
Web. For example, usehttps://www.example.com/dk/
. -
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';
- Alternative (All Webservers): Create a
-
-
Verify that cookies (e.g.,
PHPSESSID
) are set correctly in HTTP responses to ensure session data aligns with the store. -
Check for additional rewrites or redirects that might interfere with routing.
-
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
-
-
Test access to various pages in the Denmark store view after applying these changes.
Related reading
- Set up multiple websites or stores in Commerce on Cloud Guide