1

Whenever I am hitting the URL https://localhost:9002/trainingstorefront/?site=electronics, it always redirects to the site homepage. How this request mapping actually happens and where does it decide that which is the site to be loaded.

2 Answers2

2

Site mapping is done through regex (urlPatterns) which you can find under your CMSSite.

$siteUid=electronics
# CMS Site                                                                                                 
INSERT_UPDATE CMSSite ; uid[unique=true] ; urlPatterns                                                                                                                  ;      
                      ; $siteUid         ; (?i)^https?://[^/]+(/[^?]*)?\?(.*\&)?(site=$siteUid)(|\&.*)$,(?i)^https?://$siteUid\.[^/]+(|/.*|\?.*)$;

As you see here, (?i)^https?://[^/]+(/[^?]*)?\?(.*\&)?(site=$siteUid)(|\&.*)$ regex is associated with electronics CMSSite. Which mean if you hit https://localhost:9002/trainingstorefront/?site=electronics URL it land with electronics site.

You can change this urlPatterns regex as per your requirement.
e.g. I want the user to land on the electronics site when they hit https://localhost:9002/trainingstorefront/ (without ?site=electronics), to achieve this I'll add (?i)^https?://[^/].*$ to urlPatterns

$siteUid=electronics
# CMS Site 
INSERT_UPDATE CMSSite ; uid[unique=true] ; urlPatterns                                                                                                                  ;      
                      ; $siteUid         ; (?i)^https?://[^/]+(/[^?]*)?\?(.*\&)?(site=$siteUid)(|\&.*)$,(?i)^https?://$siteUid\.[^/]+(|/.*|\?.*)$,(?i)^https?://[^/].*$ ;
HybrisHelp
  • 5,518
  • 2
  • 27
  • 65
  • 1
    Keep in mind that once the session is established, the CMS Site cannot be changed or by using the "clear" parameter. – Johannes von Zmuda Sep 07 '20 at 10:53
  • Yes, because during the very first request it adds a matching CMSsite to the session so that subsequent request serves for the same CMSsite. – HybrisHelp Sep 07 '20 at 13:57
0

For this, you must be aware of the filter chain that is used before any url is actually handled by a controller. This filter chain list can be easily found in the storefront web folder.

The Url is mapped using the CMSSiteFilter present in your storefront extension.

For the whole list of such filter, check spring-filter-config.xml in your storefront extension.