On our Magento store the sitemap which Magento automatically generates from the admin panel at Catalog > Google Sitemap adds the home url to our homepage like:


Is there a way to change it to


you are getting that url because the homepage is a CMS page.
In your case it has the identifier home.
In order to change that url you need to rewrite the method Mage_Sitemap_Model_Resource_Cms_Page::_prepareObject and make it look like this:

protected function _prepareObject(array $data)
    $object = new Varien_Object();
    //for home set url to ''
    if ($data['url'] == 'home') {
        $data['url'] = '';

    return $object;

of course this won't work if you change the homepage to an other page. But it's a quick way of doing it.
If you want the clean version you have to check what is the hompage for your current store.
For this add a new member and method like this:

protected $_homeId = array();
public function getHomepageId($storeId)
    if (!isset($this->_homeId[$storeId]))) {
        $pageId = Mage::getStoreConfig(Mage_Cms_Helper_Page::XML_PATH_HOME_PAGE, $storeId);
        $delimeterPosition = strrpos($pageId, '|');
        if ($delimeterPosition) {
            $pageId = substr($pageId, 0, $delimeterPosition);
        $this->_homeId[$storeId] = $pageId;
    return $this->_homeId[$storeId];

In this case, you need to modify the getCollection method in the same class. Before $page = $this->_prepareObject($row); add this:

if ($row[$this->getIdFieldName()] == $this->getHomepageId($store)) {
    $row['url'] = '';
  • so I will need to override app/code/core/Mage/Sitemap/Model/Resource/Cms/Page.php as described here – Holly Nov 17 '14 at 12:06
  • @CreedBratton. Yep...that's what I'm saying. – Marius Nov 17 '14 at 12:07
  • great - thanks for your help. I have a simlar question here would you mind looking at it? – Holly Nov 17 '14 at 12:09
  • @MariusI tried this and found that the value are logging correctly in my custom log file but when I check at mysite.com/sitemap/sitemap.xml, it is still showing mysite.com/home instead of mysite.com. Is there any need for cache clear/compilation run or something like that? – Anurag Khandelwal Mar 27 '17 at 9:21

Magento added two events to adjust product and category XML sitemap:

  • sitemap_categories_generating_before
  • sitemap_products_generating_before

In Mage_Sitemap_Model_Sitemap::generateXml() they replaced

    foreach ($collection as $item) {


    $priority   = (string)Mage::getStoreConfig('sitemap/product/priority', $storeId);
    $collection = Mage::getResourceModel('sitemap/catalog_product')->getCollection($storeId);
    $products = new Varien_Object();
    Mage::dispatchEvent('sitemap_products_generating_before', array(
        'collection' => $products
    foreach ($products->getItems() as $item) {

Same for category pages, but 20 lines below they just kept foreach ($collection as $item) for CMS pages. I'd would adapt this method and rewrite/modify Mage_Sitemap_Model_Sitemap to replace it with ...

    $pages = new Varien_Object();
    Mage::dispatchEvent('sitemap_cms_pages_generating_before', array(
        'collection' => $pages,
        'store_id' => $storeId
    foreach ($pages->getItems() as $item) {

Then you can use that new event to modify your CMS pages sitemap:




public function renameCmsHomePageUrl(Varien_Event_Observer $observer)
    $collection = $observer->getCollection();
    foreach ($collection->getItems() as $item) {
        if ($item->getUrl() === 'home') {

Thanks for the code.

Using this snippet, I have created an extension to automate this process. This will work with mult-store/site configurations too. In this extension, I have updated the CMS Sitemap link generation like the follows:

     * Generate cms pages sitemap
    $homepage = (string)Mage::getStoreConfig('web/default/cms_home_page', $storeId);
    $changefreq = (string)Mage::getStoreConfig('sitemap/page/changefreq', $storeId);
    $priority   = (string)Mage::getStoreConfig('sitemap/page/priority', $storeId);
    $collection = Mage::getResourceModel('sitemap/cms_page')->getCollection($storeId);
    foreach ($collection as $item) {
        /* Customizing sitemap generation where url key is home */
        Mage::log($item->getUrl(), NULL, 'SeoSitemap.log');
        $url = $item->getUrl();
        if ( $item->getUrl() == $homepage) {
            $url = '';
        $xml = sprintf('<url><loc>%s</loc><lastmod>%s</lastmod><changefreq>%s</changefreq><priority>%.1f</priority></url>',
            htmlspecialchars($baseUrl . $url),
        /* Customization ends */


    $this->setSitemapTime(Mage::getSingleton('core/date')->gmtDate('Y-m-d H:i:s'));

    return $this;

You can find the entire source-code from my repository

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.