cancel
Showing results for 
Search instead for 
Did you mean: 

Single Domain, Multiple sites - Cookie issue?

0 Kudos

We need 2 websites in our shop. The urls are localhost:9001/mystorefront/site1 and localhost:9001/mystorefront/site2. When I have opened 1 site and if I try to open next site in other tab then it is showing page not found. I found out that this issue is due to cookie setup. There is a cookie like "localhost:9001/mystorefront/"

I have changed EnhancedCookieGenerator like this.

From: cookie.setPath(request.getContextPath());

To: cookie.setPath(request.getContextPath() + request.getServletPath());

After the change, If I see my cookies in my browser there is cookie like "localhost:9001/mystorefront/site1/" but the cookie "localhost:9001/mystorefront/" is also still there.

The problem still is there. Any suggestions will be helpful.

Thanks.

Former Member
0 Kudos

You could try adding ?site=site1&clear=true

Accepted Solutions (0)

Answers (4)

Answers (4)

Former Member
0 Kudos

Hi Sindhu,

We have two sites in one storefront. i'm faing the same isse. can you please let me know what you have done to resolve this issue?

Thanks,

Ram

Former Member
0 Kudos

Hi Rossner,

Previously our project website have two sites,now now requirement is they need 4 websites to our project website.I did, like what you suggest on the above solution,its working fine for two sites. For 4 sites requirement in witch place have to change the code .Please suggest me.Its urgent.Kindly help. Than you...Sindhu

Former Member
0 Kudos

Hi Rossner,

its working for me after i changed to according to mysite url, thank you....

Former Member
0 Kudos

I have seen this before. The problem is your JSESSIONID cookie. The enhanced cookie generator is used for some other cookies (like cart for example). You basically need to rewrite the cookie header. I used this to do it:

 package de.hybris.platform.yacceleratorstorefront.security.cookie;
  
 import org.apache.log4j.Logger;
  
 import javax.servlet.http.HttpServletResponse;
  
 import static de.hybris.platform.yacceleratorstorefront.security.cookie.EnhancedCookieGenerator.HEADER_COOKIE;
  
 public class CookieHeaderAdjuster {
  
     private final static Logger LOG = Logger.getLogger(CookieHeaderAdjuster.class);
  
     public void adjustCookieHeader(String path, HttpServletResponse response) {
  
         if (response.containsHeader(HEADER_COOKIE)) {
  
             String currentValue = response.getHeader(HEADER_COOKIE);
  
             if (currentValue.contains("JSESSIONID")) {
                 String updatedValue = currentValue.replaceAll("(JSESSIONID=[0-9A-Z]+; Path=)[^;]+(;.*)", "$1" + path + "$2");
                 if (LOG.isDebugEnabled()) {
                     LOG.debug("Changing cookie header from \"" + currentValue + "\" to \"" + updatedValue + "\"");
                 }
                 response.setHeader(HEADER_COOKIE, updatedValue);
             }
         }
     }
 }

Then you need to call it from some places, the CMSSiteFilter

 cmsSiteModel = getContextInformationLoader().initializeSiteFromRequest(absoluteURL);
  
 // FIX COOKIE PATH
 if (cmsSiteModel != null) {
    cookieHeaderAdjuster.adjustCookieHeader("/" + cmsSiteModel.getUid(), httpResponse);
 }

I think I had also updated the enhanced generator, and as I recall there was a remember me cookie as well.

Another option is to do it in Apache using mod_rewrite. This can work well if you only have 2 sites and then you don't have to change any code.

Former Member
0 Kudos

Hi Rossner,

its not working,redirecting to HAC and while debuging in EnhancedCookieGenerator the cookie.getDomain() value is null.why?

Please suggest me .

Thank you...