Joomla | Rewrite Xmap URL to /sitemap.xml SEF URL

Xmap is a great automatic sitemap generator for the joomla content management system.

It produces HTML (For your users) XML (for search engines) and news (Please fill me in!)

The URL's to these sitemaps however are not so search engine friendly.

 

This can easily be fixed in your .htaccess file.

To Rewrite the Xmap URL

First you need to check the actual url of the sitemap you want to change.

From the component menu, click on Xmap, then click on the options tab of your sitemap. Here you will see the urls for your sitemaps. Lets use the xml as an example.

Click on the xml link, then copy the url and remove your domain name. The default one looks like this:

/index.php?option=com_xmap&sitemap=1&view=xml

This may be slightly different depending on your version of xmap, your current htaccess rules and if you are running any sef extensions.

To rewrite the example above, you would add this to your htaccess file.

RewriteCond %{REQUEST_URI} ^/sitemap.xml
RewriteRule .* /index.php?option=com_xmap&sitemap=1&view=xml

Now, when you visit your site at www.mysite.com/sitemap.xml your xml sitemap will be displayed.

This is the first place a search engine will look for a sitemap xml file without you submiting it directly to them!

To Rewrite the Xmap URL when using Joomfish

Xmap splits languages into different sitemaps. The rule above will not work to direct to different languages eg.

en/sitemap.xml
fr/sitemap.xml

 

To continue with this example of a French/English site, the 2 xml sitemaps would be located (defaultly) at:

/en/index.php?option=com_xmap&sitemap=1&view=xml

 

/fr/index.php?option=com_xmap&sitemap=1&view=xml

 

For this we need 3 rules, 1 for each language and 1 for the default /sitemap.xml so we use:

RewriteCond %{REQUEST_URI} ^/sitemap.xml
RewriteRule .* /index.php?option=com_xmap&sitemap=1&view=xml

 

RewriteCond %{REQUEST_URI} ^/en/sitemap.xml
RewriteRule .* /en/index.php?option=com_xmap&sitemap=1&view=xml

 

RewriteCond %{REQUEST_URI} ^/fr/sitemap.xml
RewriteRule .* /fr/index.php?option=com_xmap&sitemap=1&view=xml

As pointed out in the comments below, only one rule is actually needed to rewrite all sitemaps to the correct language:

RewriteRule ^(.*)sitemap.xml$ /$1index.php?option=com_xmap&sitemap=1&view=xml [L]

Now, if you have the automatic language detection enabled in the joomfish plugin, /sitmap.xml will show the local language or the language of the previously viewed page. /fr/sitemap.xml and /en/sitemap.xml will show the correct languages.

Remember to replace the original sitemap url with the one that appears in your browser after clicking on the link in preferences. Not just the link, incase it is adhearing to any other rules, redirects or rewrites.

If anyone has a better way of writing the multi-language rules, please let me know!

Now you have a good url you should also add it to the top of your robots.txt file right at the top, then leave a blank line, like so:

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

User-agent: *