cancel
Showing results for 
Search instead for 
Did you mean: 

Url pattern and configuration for multiple websites with same domain but different context ?

Former Member

Want to know the best approach for url mapping/patterns when we have multiple websites which have same domain name but context is varying like:

site1: www.domain.com/site1

site2: www.domain.com/site2

.....

In this scenario how should I approach:

1) Having single storefront. Keeping the configuration changes in url at web server and make the required changes to map the url pattern of website in hybris. Also Making the webroot of storefront extension as blank.

2) Create separate storefront extensions with varying webroot. And create url pattern based on that.

3) Any other approach?

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi,

I think 1st approach is better because you will avoid code duplication. It will be just easier to maintain it if new version appears.

You can use CMSSite.urlEncodingAttributes and include storefront in it. This way site id will be always included in the URL.

On the other hand you need to read site id it from URL, this can be done with CMSSite.urlPatterns. Something like this:

 (?i)^https?://[^/]+(/[^?]*)?/site1/\w+\??.*$

This will read site1 id from URL and set it for the request, so you won't end up with 500 - Cannot find CMSSite associated with current URL.

Also you can see there is no customization needed to achieve this.

0 Kudos

Hi,

you might want to adjust CMSSiteFilter:processNormalRequest() and make sure that getContextInformationLoader().initializeSiteFromRequest(..) is called every time so that site switching would work

Answers (2)

Answers (2)

ArthurPerry
Employee
Employee

Using a single storefront web context it will be necessary to add the /site1 and /site2 path to the session cookie. Otherwise the sites will share the session and this can cause many headaches (such as if product availability or prices differ per site.) Look at the EnhancedCookieGenerator class.

Former Member
0 Kudos

Hi Perry,

How we set "single storefront web context session cookie"?

ArthurPerry
Employee
Employee
0 Kudos

It is set in the de.hybris.platform.yacceleratorstorefront.security.cookie.EnhancedCookieGenerator class in the yacceleratorstorefront extension. This extension is distributed with source code so you can inspect it and understand how it configures the session cookie. You need to set the path on the cookie to ensure that you have separate sessions for each site.

Former Member
0 Kudos

Hi Perry, I am facing this issue, I have two sites with same domain with different context path. Site URL pattern is set correctly and I also updated setEnhancedCookiePath() of EnhancedCookieGenerator. But I noticed this class is getting called for only secure request and not for http requests, for http request cookie is getting generated in same path. Please suggest.

Former Member
0 Kudos

We are having problem since version 5.5.1 setting to contexts for the same extension, and it's related with XSSSiteFilter and de.hybris.platform.util.Utilities.

For example, trying to have two different contexts for cmscockpit:
                           <Context path="/cmscockpit" docBase="C:\dev\puntroma\hybris\bin\ext-commerce\btgcockpit/web/webroot" >
                 <Manager pathname="" />
                 <Loader platformHome="C:\dev\puntroma\hybris\bin\platform" className="de.hybris.tomcat.HybrisWebappLoader" deployName="default" />
             </Context>
             
             <Context path="/cmscockpit2" docBase="C:\dev\puntroma\hybris\bin\ext-commerce\btgcockpit/web/webroot" >
                 <Manager pathname="" />
                 <Loader platformHome="C:\dev\puntroma\hybris\bin\platform" className="de.hybris.tomcat.HybrisWebappLoader" deployName="default" />
             </Context>
 


Raises the following error whenever we start the application:

java.lang.IllegalArgumentException: unknow web root '/cmscockpit2' cannot find any mapped extension at de.hybris.platform.util.Utilities.getExtensionForWebroot(Utilities.java:2990) at de.hybris.platform.servicelayer.web.DefaultXSSFilterConfig.

This was working perfectly fine with hybris v4, How can we manage this to have multiple contexts of spirng for the same extension?

Thank you very much!

Former Member
0 Kudos

Ok, adding a dummy property like:

 btgcockpit2.webroor=/cmscockpit2

Made the difference to avoid the problem starting the server.