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.

Sign Up for Our Newsletters

Get notified of the best deals on our WordPress themes.

You May Also Like
Node.js

Node.js Environment Setup

Table of Contents Hide NodeJS Installation Video TutorialInstalling Node.js and npm on Windows Operating SystemInstalling Node.js and npm on MacInstalling Node.js using XCode and HomebrewInstall Node.js on Ubuntu It’s very…
View Post