April 1, 2020
Estimated Post Reading Time ~

How to manage multi site using dispatcher in CQ / WEM

Use Case:
1) You have a multi-language site and you want to have different dispatcher configuration for them
2) Activating pages under English site should not flush pages under french site for example
3) I have different URL for each site (for example en.mysite.com and fr.mysite.com)

Solution:
At Publish Instance

First of all, In order to manage the multi-domain multi-language site, You should have a proper mapping rule within CQ. Please see http://dev.day.com/content/kb/home/cq5/CQ5SystemAdministration/HowToMapDomains.html for that

Now what this is going to do is, make sure that your links are properly written when you open any page under a different domain.

Example of sample /etc/map

map
+-- http
+-- any_geometrixx.de (nodetyp: sling:Mapping)
property: internalRedirect : /content/geometrixx/de.html
property: sling:match : .*.*geometrixx.de.(4503|80)+/$
+-- libs (nodetyp: sling:Mapping)
property: internalRedirect: /libs
+-- etc (nodetyp: sling:Mapping)
+-- designs (nodetyp: sling:Mapping)
property: internalRedirect: /etc/designs
+-- any_geometrixx.en (nodetyp: sling:Mapping)
property: internalRedireect: /content/geometrixx/en.html
property: sling:match : .*.*geometrixx.en.(4503|80)+/$
+-- libs (nodetyp: sling:Mapping)
property: internalRedirect: /libs
+-- etc (nodetyp: sling:Mapping)
+-- designs (nodetyp: sling:Mapping)
property: internalRedirect: /etc/designs

At Dispatcher
First of all, you have to associate the dispatcher handler with each incoming domain. You can use Name Virtual Host for this

better to create a different farm for different domain

# Each farm configures a set of load-balanced renders (i.e. remote servers)
/farms
{
$include farm*.any
}

Suppose you have two farms,

farm_site1.any
farm_site2.any

Then you will have virtual host setting as,

/virtualhosts
{

"*site1*"
}

/renders
{
$include "renders.any"
}

/cache
/docroot "<Global Doc root>/site1"

And

/virtualhosts {

"*site2*"
}

/renders
{
$include "renders.any"
}

/cache
/docroot "<Global Doc root>/site2"

You can have the same or different renderers for different sites.

Now at your virtual host setting, you will configure different doc root for a different site

NameVirtualHost *:80

<VirtualHost *:80>
ServerName site1.com
#This is to handle dev enviornments
ServerAlias *.site1.com
DocumentRoot <Global Doc root>/site1
Include <Configurations specific to site1>

</VirtualHost>

<VirtualHost *:80>
ServerName site2.com
#This is to handle dev enviornments
ServerAlias *.site2.com
DocumentRoot <Global Doc root>/site2
Include <Configurations specific to site2>

</VirtualHost>
DocumentRoot <Global Doc root>


Now to handle dispatcher flush request for specific site path, You can have rule like,

SetEnvIfNoCase CQ-Path ^/content/site1 hostnameforfarm=site1.com
SetEnvIfNoCase CQ-Path ^/content/site2 hostnameforfarm=site2.com
RequestHeader set Host %{hostnameforfarm}e env= hostnameforfarm

Now above rule will set the hostname for dispatcher based on {CQ-Path} in a flush request. That means if something under site1 get activated site2 cache will NOT be flushed.


By aem4beginner

No comments:

Post a Comment

If you have any doubts or questions, please let us know.