Using sitemap.xml in Magento 1

in Magento

Enabling sitemap.xml in Magento

Configure Magento to create sitemaps

  • To enable sitemaps inside Magento, log in to your admin
  • Make sure your crontab is working properly
  • Navigate to System > Configuration > Catalog > Google Sitemap > Generation Settings

Now fill in the information:

Creating a sitemap.xml in Magento

When the generation of sitemaps is enabled in the catalog settings, we should make sure a sitemap.xml is created.

  • Navigate to Catalog > Google Sitemap > Add Sitemap
  • Add a sitemap.xml file to the configuration:
    add_sitemap-xml

If you use only one sitemap for all storefronts, just use / as path. If you want to use multiple sitemap.xml files depending on your storefront create a sitemap directory in /data/web/public, a directory named after each storefront to save each sitemap.xml on a different location.

Generate the sitemap manually

After adding a sitemap to the Magento configuration, we’ll make sure the sitemap exists by clicking the “generate” button on the far right of the page:
sitemap_generate

Configuring nginx to use the same sitemap for all storefronts

There is no configuration needed for Nginx when you use one sitemap for all storefronts. As there is only one sitemap.xml, Google and other search engines, will use the same sitemap for all sites.

Configure Nginx to use a sitemap.xml per storefront

To configure multiple sitemaps, you need to add some configuration:

  • Make sure there is no sitemap in /data/web/public/sitemap.xml to avoid an incorrect sitemap to be served (change the location of the sitemap.xml in Magento from /sitemap.xml to /sitemaps/$storecode/sitemap.xml where $storecode is the name of your storefront)

  • Create a sitemap directory and a directory for your storefront:

for CODE in $(n98-magerun sys:store:list --format csv | sed 1d | cut -d "," -f 2 )
do
mkdir -p /data/web/public/sitemaps/$CODE
done
  • Create an Nginx include as /data/web/nginx/server.sitemap to route all requests to sitemap.xml to the given store:
location /sitemap.xml {
    rewrite ^/sitemap\.xml$ /sitemaps/$storecode/sitemap.xml;
}

Now test your sitemap by requesting and verify whether the right sitemap is served:

curl -v https://www.example.com/sitemap.xml

Alternative configurations

Configure nginx to serve a sitemap.xml outside the public directory

In case the sitemap.xml is created outside the public webroot, you can’t use a rewrite construction to serve your sitemap as the file is not public accessible.
To circumvent this, you can use the nginx alias feature to create an alias to a file outside the public webroot:

location /sitemap.xml {
    alias /data/web/magento/sitemap.xml;
}

Configure sitemaps when storecode to url is enabled

Use the following configuration if storecode to url is enabled in your webshop and no $storecode variable is set:

location ~ .+/sitemap.xml {
    rewrite ^/([^/]+)/sitemap\.xml$ /sitemaps/$1/sitemap.xml;
}

Add your sitemap location to your robots.txt

When you can successfully request your sitemap.xml, add it to your robots.txt:

Sitemap: http://www.example.com/sitemap.xml

Troubleshooting

We’ve seen one or two special cases where creating a sitemap was extremely slow. This was caused by some queries that took sometimes 10 minutes (!) to complete.
In this very specific case the solution was to disable use_index_extensions in mysql.
To do this, add SET SESSION optimizer_switch='use_index_extensions=on' to the mysql initStatements in your local.xml:

<connection>
    <host><![CDATA[mysqlmaster]]></host>
    <username><![CDATA[app]]></username>
    <password><![CDATA[somepass]]></password>
    <dbname><![CDATA[magento_db]]></dbname>
    <initStatements><![CDATA[SET NAMES utf8; SET SESSION optimizer_switch='use_index_extensions=on';]]></initStatements>
    <model><![CDATA[mysql4]]></model>
    <type><![CDATA[pdo_mysql]]></type>
    <pdoType><![CDATA[]]></pdoType>
    <active>1</active>
</connection>

Additional links

There is lots of information about setting up and pushing your sitemap to Google and other search indexes.

See:

0