Optimise Magento XML Sitemap
The automatic XML sitemap of Magento has been documented on several occasions as a useful tool for Magento SEO. One thing that’s always bugged me about it however is the fact that by default it indexes the homepage as http://www.yourdomain.com/home rather than just http://www.yourdomain.com. This can be fixed pretty easily because the sitemap is configured by one simple PHP file in the core.
1. Open app> code > core > Mage > Sitemap > Model > Sitemap.php duplicate this locally to create app> code > local > Mage > Sitemap > Model > Sitemap.php
Find the line of code which should be on line 176 which contains the foreach statement. It’s just a simple if statement that checks the variable brought back by $item->getUrl(). If the value is not “home”, run the normal script. If it is “home” it removes the baseUrl extension of . $item->getUrl(). Below is the finished code, I have marked in bold below are the parts that I have added.
foreach ($collection as $item) {
if ($item->getUrl() != "home") {
$xml = sprintf('<url><loc>%s</loc><lastmod>%s</lastmod><changefreq>%s</changefreq><priority>%.1f</priority></url>',
htmlspecialchars($baseUrl . $item->getUrl()),
$date,
$changefreq,
$priority
);
} else {
$xml = sprintf('<url><loc>%s</loc><lastmod>%s</lastmod><changefreq>%s</changefreq><priority>%.1f</priority></url>',
htmlspecialchars($baseUrl),
$date,
$changefreq,
$priority
);
}
$io->streamWrite($xml);
}
Thanks for reading the Magento blog at ecommerce web design, hope this helps everyone with their Magento SEO.

Adam,
Thanks for this useful tip! One question… what do you mean “duplicate this locally”?
Thanks,
Craig
Adam,
Very important point. Excellent post and works like a charm!
Thanks,
Craig
Hi Craig, by duplicate locally I mean that you need to create a copy of the file in your app/code/local folder.
For example, if your file was:
app/code/core/Mage/Template/Navigation.php
you’d create:
app/code/local/Mage/Template/Navigation.php
The local copy of the file will be used instead of the core copy!
Hi, thanks for the article. I’ve just changed my Sitemap.php, regenerated the sitemap, but the change doesn’t show up? Am I missing something?
Same here… no changes when using new code in local or even changing the original Sitemap.php (Magento 1.4.1.1)
It works like a charm. If you use Compilation, make sure you recompile the site and regenerate the sitemap to see the changes. Thank you!
Great job! Adam! it just solves my question about Magento Sitemap.
thanks, works like a charm.
P.S. to make changes take effects, i had to “run compilation process” (system->tools->compilation)