Unique sitemap.xml files for Drupal Multi-site setup

Problem: We have 3 Drupal sites that are set up as a multi-site installation. The advantage of this is that we can share user tables, which are in turn replicated on the main FEN authentication server. The down side to this is that the existing Sitemaps module will not work with this multi-site config because the sitemap.xml has to be in the root directory for each of the sites i.e.

http://blogs.familyeducation.com/sitemap.xml
http://comments.familyeducation.com/sitemap.xml
http://forums.familyeducation.com/sitemap.xml

These links currenty link to a unique sitemap.xml for each of the domains. This wasn't the case when using the Sitemap module. Because there could be only 1 sitemap.xml in the document root file, which is shared in the case of a multi-site install. The sitemap.xml would be overwritten by the last time the module was called and would not reflect the actual site.

These sitemaps are required by Google analytics and they must be in the format described by: http://www.sitemaps.org

Solution using Drupal 5.x

I created a view for each of the sites to output the pertinent data in the sitemap.xml format. I then wrote the famed_sitemap.module which would call the appropriate sitemap for a given site.

This solution also required a rewrite rule in Apache so that the request would be directed to the actual location of the sitemap based on the domain name. To the visitor/google the sitemap.xml file appeared to be in the root directory. For example http://blogs.familyeducation.com/sitemap.xml was actually in http://blogs.familyeducation.com/sitemaps/blogs/sitemap.xml. This was necessary so that their could be a unique sitemap.xml file for each Drupal site. Here is the Apache Redirect:

# Sitemap rewrite rule
RewriteRule ^/(sitemap[0-9]*\.xml)$ /site/html/sitemaps/%{SERVER_NAME}/$1 [L]

famed_sitemap.module is attached below.

AttachmentSize
famed_sitemap.module3.52 KB
Your rating: None Average: 5 (3 votes)