XML Sitemap Usage and Configuration

The XML Sitemap Generator is already added to your SCORE solution.  But to use it, you must first configure specific properties in your Sitecore <site> definition, and add an event handler to "kick-off" the generation of the sitemap for a specific tenant website.

Step 1 - Adding <site> Configuration Properties

For each site that you wish to generate a Sitemap, you must define 2 properties of the site configuration - xmlSitemapFilename and targetHostName.

Sample Site Configuration
<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">
  <sitecore>
    <sites>
      <site patch:before="site[@name='website']" name="score" virtualFolder="/" physicalFolder="/" requireLogin="false"
            rootPath="/sitecore/content/scoretest" hostName="score" 
            targetHostName="score" xmlSitemapFilename="Score123.xml"
            startItem="/home" database="web" domain="extranet" allowDebug="true" cacheHtml="true" htmlCacheSize="10MB"
            registryCacheSize="0" viewStateCacheSize="0" xslCacheSize="5MB" filteredItemsCacheSize="2MB" enablePreview="true"
            enableWebEdit="true" enableDebugger="true" disableClientData="false"/>
    </sites>
  </sitecore>
</configuration> 

SCORE 2.1.27.0 and higher

Optional site configuration attribute

sharedPages - Sitecore Item IDs of pages and their descendant children which are stored not in the Site RootPath, but should trigger sitemap generation for this particular site when item published.
Example: sharedPages="{A4D461C4-8D86-4A0A-BD1E-9DA690AE8819}|{E8A302BF-83B1-495B-9656-AFAF1206889F}" 

 

Step 2 - Registering an Event Handler to Build the Map

The next step is to add an event handler to kickoff the sitemap building process.   SCORE provides an event handler for this purpose that can be added to your Sitecore configuration.  Based on the hosting and configuration of your website, there are a number of events that you can add this handler to in order to generate the map when your website requires it.

Single Server Sitecore Configuration

One example is adding the event handler provided by SCORE to the publish:end.   you would use this event if to generate a sitemap on completion of publishing on the content management server.  So if you use a single server configuration, or for some reason want the XML sitemap to be generated on the CM server, you can wire the processor into this event.

SingleServer.PublishXMLSitemap.config
<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">
  <sitecore>
    <events>
      <event name="publish:end">
        <handler type="Score.Custom.Handlers.GenerateXmlSitemaps, Score.Custom" method="GenerateMaps" />           
      </event>      
    </events>
  </sitecore>
</configuration> 

Separate CM + CD Sitecore Configuration

The more common configuration for Sitecore is to separate the CM and CD servers into separate machines.  

In this scenario, Sitecore can use the remote event queue to submit an event from the CM server to the CD server using an event called publish:end:remote.  This event is called on the Content Delivery server once a publish operation has ended.

CDServer.PublishXMLSitemap.config
<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">
  <sitecore>
    <events>
      <event name="publish:end:remote">
        <handler type="Score.Custom.Handlers.GenerateXmlSitemaps, Score.Custom" method="GenerateMaps" />           
      </event>      
    </events>
  </sitecore>
</configuration>