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.

 

0 Shares
Leave a Reply

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

You May Also Like
XOR in Python

XOR in Python

XOR Operator in Python is also known as “exclusive or”  that compares two binary numbers bitwise if two bits are…
How To

How to configure Git proxy?

If you are working in the corporate company all the internet requests usually goes through the corporate firewall.…