Handling Multiple Hostnames in a Sitecore Multi-Site Solution
A small little gotcha came by today as I was working on a multi-site Sitecore solution for sites on multiple domains. I saw a question on Stack Overflow which is in fact a question I needed to know the answer to myself. It had to do with binding a site on both a subdomain and no subdomain for the same Sitecore site of a multi-site solution.
Sitecore’s <site ... /> nodes have an optional hostName attribute to bind that specific site to match on the provided host. This is a filter to determine which site to put in context based on the current request’s hostname. If none match, the last site defined (typically left as the main “website”) will be put in context. The question was about handling both a “www.site.com” host and “site.com” and how the typical hostName="*.site.com" doesn’t handle that (because it only handles any subdomains). Needing to know the answer myself I went to a good friend and fellow Sitecore developer Mark Stiles. Mark has significant experience on large scale multi-site installs so he immediately fired back a simple answer to “remove the dot.” Thus, we get hostName="*site.com". Simple, and it works, since it catches anything before the actual hostname, whether that includes a subdomain and dot or not. So if you ever need to handle any subdomain or none, change your hostName filter to not include a dot. You could alternatively pipe-delimit both the non-subdomain and the catch all subdomain.
4 Comments + Add Comment
Got anything to say? Go ahead and leave a comment!
Recent Comments
- Performance tuning your Sitecore installation | Agile and ALM: Software development today on A Going Live Checklist for Sitecore Websites
- Imran Saleem on Sitecore Avanced Database Crawler Occasionally Provides Null Results
- Ty Cahill on Sitecore Front-End Development Best Practices
- Sitecore Managed Sites as Virtual Folders | Fire Breaks Ice on Sitecore Item and Field Names
- Krimos on Using the DataSource Field with Sitecore Sublayouts
Sitecore Links
- .Sitecore
- Aboo Bolaky
- Alex Shyba
- Anders Dreyer
- aweber1.0
- Brian Pedersen
- Christopher Wojciech
- Coffee => Coder => Code
- Dev Sitecored²
- Everything Web
- Image0.com blog
- John West
- Learn Sitecore
- Let's do Sitecore
- Mark van Aalst
- Matthew Kenny
- Molten Core
- Project Lifecycle
- Sean Kearney
- Sebastian Patten
- Sitecore Australia
- Sitecore Blog
- Sitecore Climber
- Sitecore Development
- Sitecore Gadgets
- Techphoria414
- The Client View
- The Sitecore Experience
- Web Content Management and Delivery
Archives
- April 2013 (1)
- February 2013 (1)
- January 2013 (1)
- December 2012 (1)
- June 2012 (2)
- May 2012 (2)
- March 2012 (1)
- February 2012 (1)
- January 2012 (5)
- December 2011 (4)
- November 2011 (1)
- July 2011 (1)
- June 2011 (1)
- May 2011 (2)
- March 2011 (6)
- February 2011 (2)
- January 2011 (10)

Posted under:
Nice tip. Thanks.The other gotcha becomes apparent if you need to secure each hostname with SSL. For that scenario you have to have an IP address for each app as per IIS limitations. Have you tried it?
Thanks,
-Nick
Thanks for this post! I had been struggling adding a second site to a 6.4.1 installation, and adding the * to the hostname filter worked right away for me. I actually defined this filter like this: hostName=”*myhostname*” (substituting the real host names).
-S.
It should be noted that when using the wildcard(*) character Sitecore will then use the Sitecore.Text.WildCardParser class which may catch more than you’ve bargained for, if you have a domain that exists within the second domain. For example: mynewdomain.com.pl will be caught by *domain.com if the site node is first. It’s not exactly what you’d expect unless you’d written it as *domain.com*. Then you’d expect it to catch that case so be forewarned. Using the pipe delimited option may be better for you since you’ll be able to specify exactly which domains you are targeting.
Okay so I’ve logged a ticket with Sitecore about the issue. I believe there is a legitimate bug with the WildCardParser.Matches function. The issue results in two types of mismatches.
The first happens with a pattern like *domain.com.pl where it will be matched to http://www.domain.com. The second will be if you have a pattern like *domain.com* where it will not match http://www.domain.com.pl.
You’ll likely not see it if your domains aren’t closely related but if they are you’ll have to order the sites in order of most-to-least specific pattern.