Handling Multiple Hostnames in Sitecore using Wildcard

There will be scenarios where you need to target multiple hostnames to a single website. A typical scenario would be hostname with (www subdomain) and a non-www hostname.

For instance :

  1. example.com
  2. www.exmaple.com

Standard Site Definition Example with Single Hostname entry:

<site hostName="example.com" name="uswebsite" language="en"
 rootPath="/sitecore/content/uswebsite" startItem="/home" 
cacheHtml="false" virtualFolder="/" physicalFolder="/" database="web" 
domain="extranet" allowDebug="true" htmlCacheSize="10MB" 
registryCacheSize="0" viewStateCacheSize="0" xslCacheSize="5MB" 
filteredItemsCacheSize="2MB" enablePreview="true" enableWebEdit="true" 
enableDebugger="true" disableClientData="false" />

The best way to achieve this in Sitecore is through wildcards. Sitecore supports wildcard in the hostnames and with the help of wildcard multiple hostnames can be targeted in the single site definition node.

Handling Multiple Hostnames in Sitecore using Wildcard

First, let us take a look at the solution by adding the multiple domains into a single hostname field with the help of wildcard.

Site Definition Example with mutiple domains:

<site hostName="example.com | *.example.com | myanotherdomain.com" 
name="uswebsite" language="en" rootPath="/sitecore/content/uswebsite" 
startItem="/home" cacheHtml="false" virtualFolder="/" physicalFolder="/" 
database="web" domain="extranet" allowDebug="true" htmlCacheSize="10MB" 
registryCacheSize="0" viewStateCacheSize="0" xslCacheSize="5MB" 
filteredItemsCacheSize="2MB" enablePreview="true" enableWebEdit="true"
 enableDebugger="true" disableClientData="false" />

In the above example, we have added the 3 different domains with the help of wildcard and it will resolve the below domains without any issue.

  1. example.com
  2. www.example.com
  3. myanotherdomain.com

One thing to remember here is the domain names will be processed in order. Hence whatever matches the first will be processed even if the there is a second match which is more relevant than the first.

 

Leave a Reply

Your email address will not be published. Required fields are marked *

Sign Up for Our Newsletters

Subscribe to get notified of the latest articles. We will never spam you. Be a part of our ever-growing community.

You May Also Like