URLs for Localization

In Salesforce B2C Commerce, you can localize URLs. When you create a new site, the URL Rules module automatically formats your URLs according to the module configuration.

For site URLs, locales are configured as follows:

See URL Rules URL Syntax.

Note: If site URLs are configured with the locale ID as the first element of the URL (for example, /en_US/mens), B2C Commerce doesn't resolve URLs if they don't contain the locale (for example, /mens).

Standard B2C Commerce URLs

Standard B2C Commerce URLs are not enabled by default and are not optimized for SEO. This URL structure is important to understand if you are generating a locale-specific URL programmatically. Standard Demandware URLs have a a simple structure for storefront access in the following format:

<organization>-<sitename>-Site/<locale>/<pipeline name>-<startnode name>

Links to this type of address call a public pipeline-start node and can provide parameters such as category or product. You might also need these additional parameters:

cgid=category ID

pid= product ID (sku)

cid= content ID

Finding the locale in the URL

You can find the locale that is used for a user session in the URL. For single-language installations, there is always a locale named default. When using multiple locales, use <locale> instead of /default/.


URL Locale
http://<domain>/on/demandware.store/Sites-customer-Site/default/... Value default
http://<domain>/on/demandware.store/Sites-customer-Site/en_US/... Value en_US

The locale is used for the lookup of resources in the file system as well as in the database.

Generating a Locale-Specific URL Programmatically

You might want to provide two links so that your users can switch from English to Spanish on the homepage. But these links can't be hardcoded to the production instance URL because they must also be able to access the staging and sandbox instances for testing purposes.

You can access (get/set) the default locale programmatically, as shown in this example:

  var currentLocale : String = pdict.CurrentRequest.getLocale();
<isloop items="${dw.system.Site.getCurrent().getAllowedLocales()}" var="locale" status="loopStatus">
    var localeLanguage : String = new dw.util.Locale.getLocale(locale).getDisplayLanguage();
    if (localeLanguage == '') { // if the default langauge isn't defined, assume it's English localeLanguage = 'English'; }
    localeLanguage = localeLanguage.charAt(0).toUpperCase()+localeLanguage.substring(1);
  <a href="${URLUtils.http(new dw.web.URLAction('Home-Show',dw.system.Site.getCurrent().getID(),locale))}"><isprint value="${localeLanguage}"></a>
Note: You can get the default locale from the site: dw.system.Site.getCurrent().defaultLocale (Read Only)

Related Links