URLs for Localization

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

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 simple structure for storefront access in the following format:

http://<instance>-<realm>-<customer>.brand.com/on/demandware.store/
<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 can also use 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/.

Example:

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 and in the database.

Generating a Locale-Specific URL Programmatically

You can 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. The links must also be able to access the staging and sandbox instances for testing purposes.

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

<isscript>
  var currentLocale : String = pdict.CurrentRequest.getLocale();
</isscript>
<span>${currentLocale}</span>
<isloop items="${dw.system.Site.getCurrent().getAllowedLocales()}" var="locale" status="loopStatus">
  <isscript>
    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);
  </isscript>
  <a href="${URLUtils.http(new dw.web.URLAction('Home-Show',dw.system.Site.getCurrent().getID(),locale))}"><isprint value="${localeLanguage}"></a>
</isloop>
Note: You can get the default locale from the site: dw.system.Site.getCurrent().defaultLocale (Read Only)