Thursday, April 17, 2008

Share site resources among several sites

If you have lots of sites with similar structure and presentation layer you can make them use resources of one Sitecore site from web.config file. To do this you can create custom SiteResolver and insert it in <httprequestbegin> pipeline just after the native SiteResolver processor.
Using this approach you should have custom SiteResolver processor and special config file where you can map your sites to the same instance of Sitecore site from web.config file. It shows you how you can set several host names for the same Sitecore site in web.config file.
NOTE: This approach is supposed to have “website” site in your web.config file.
Using this idea you can set not only host names but the whole site configuration for the same Sitecore site. In that case you will be able to share cache and other resources among several sites.
Below are the steps how to apply this approach:
1) Create custom SiteResolver and set add it in web.config file just after the native SiteResolver processor, as shown below:
<httprequestbegin>
………………
<processor type="Sitecore.Pipelines.HttpRequest.SiteResolver, Sitecore.Kernel" />
<processor type="SiteMapper.Pipelines.HttpRequest. SimilarSitesResolver, SiteMapper" />
………………
</httprequestbegin>

2) Create special config file (similar.sites.config) to map your sites with the following structure:
<sites>
<site mode="on" name="www.mysite" hostname="www.mysite.dk" language="da-DK" />
<site mode="on" name="www.mysite" hostname="www.mysite.uk" language="en-GB" />
<site mode="on" name="www.mysite" hostname="www.mysite.com" language="en" />
</sites>

As you can see all three sites have the same “name”. This name determine which site from web.config file should be used when you request any of these sites.
Example of web.config file:
<!-- ***** www.mysite group ***** -->
<site mode="on" name="www.mysite" hostname=" www.mysite.com" language="en" virtualfolder="/" physicalfolder="/" rootpath="/sitecore/content" startitem="/www.mysite/home" database="web" domain="extranet" allowdebug="true" cachehtml="true" htmlcachesize="10MB" enablepreview="true" enablewebedit="true" enabledebugger="true" disableclientdata="false" />
<!-- “website” is compulsory for this solution -->
<site name="website" virtualfolder="/" physicalfolder="/" rootpath="/sitecore/content" startitem="/flugger/home" database="master" domain="extranet" allowdebug="true" cachehtml="true" htmlcachesize="10MB" enablepreview="true" enablewebedit="true" enabledebugger="true" disableclientdata="false" />

NOTE: each Sitecore site in web.config file must have hostName attribute. Otherwise Sitecore will classify this site as a default website and you won’t get required results.

Here is Sitecore package.