Create a Google Sitemap for your website

A Google Sitemap is a very important element for ranking of your website : it is used to tell Google which pages it must include in his engine. It also helps your new pages to be ranked quicker, and to be sure that all your relevant content is indexed.

A Sitemap, it’s basically a map of your website (I hope you already guessed it); a tree of pages in which the level of importance of certain pages over some other pages is cleary visible.

Of course, it’s not mandatory to create a Sitemap for your website, its purpose is especially to help Google (then also yourself). It is possible that not all the pages you included in your Sitemap will be added in Google. Even if you show him the way, Google isn’t dumb, it will only rank pages that are really relevant.

This means that you should give up for contact pages, help pages, or any other page that is not relevant. Rather than this, try to rank your « best » pages, those that have content of quality.

Depending on how your website is build (static website or dynamic website), the way to build your sitemap may vary. This article will show you some common ways to do it.

At any time, you should refer to the Google documentation about Sitemaps.

Create a static Sitemap

When I say static, I mean a Sitemap you have make yourself, line by line, and that won’t update itself automatically. That’s what we normally use for websites that only have static contents, pure HTML.

To do this, don’t waste your time in writing it yourself, you can rather use an automatic Sitemap generator. You can also use it for a dynamic website that doesn’t rewrite URLs, but you will have to generate it everytime you want to update it (usally, often) – this is something you’ll forget to do, for sure.

Create a dynamic Sitemap

A dynamic Sitemap will update itself automatically, which is useful if you update your website on a regular basis. The method given here is using URL Rewriting to make it more clean and simple.

First, create a .htaccess file, located at the root, or modify the .htaccess file you may already have :


Options +FollowSymlinks
RewriteEngine on

# Link for the Sitemap
RewriteRule ^sitemap\.xml$ /sitemap.php [L,NC]

This way, sitemap.php will allow us to automatically generate the content of the XML file (the real Sitemap). Each time Google will try to open sitemap.xml, sitemap.php will be executed and will make an update of the XML « file ».

Create a file named sitemap.php. In the example bellow, we get the content of articles of an imaginary blog.

The structure of the table used in the example bellow :


CREATE TABLE IF NOT EXISTS `blog` (
`id` mediumint(9) NOT NULL COMMENT ‘ID of the article’,
`texte` text NOT NULL COMMENT ‘Text of the article’,
`date` date NOT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COMMENT=’Articles of blog’;

The content of the file sitemap.php :

// MySQL Connection$host = “localhost”;
// normally, it’s localhost
$user = “USERNAME”;
$pass = “PASSWORD”;
$bdd = “NOM_OF_THE_DB”;

@mysql_connect($host,$user,$pass) or die(“Unable to connect : “.mysql_error());
@mysql_select_db(“$bdd”) or die(“Unable to select dabatase : “.mysql_error());

// Indicate file type : XML document
header(“Content-Type: text/xml”);

// MySQL query to get articles of the blog
$requete = “SELECT id, date FROM blog ORDER BY date DESC”;
$resultat = mysql_query($requete);

// Writing of the XML file
// Headers :
$sm = ”;
$sm .= ‘xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance”
xsi:schemaLocation=”http://www.google.com/schemas/sitemap/0.84
http://www.google.com/schemas/sitemap/0.84/sitemap.xsd”>’;

// Articles of the blog
while ($blog=mysql_fetch_array($resultat,MYSQL_ASSOC)) {
$sm .= ‘‘;
$sm .= ‘http://yoursite.com/blog?id=’.$blog[‘id’].’‘; // you may adapt the URL syntax to your need, this is an example
$sm .= ‘‘.$blog[‘date’].’‘;
$sm .= ‘monthly‘;
$sm .= ‘0.7‘;
$sm .= ‘
‘;
}

$sm .= ”;

echo $sm;

As you may guess, the Sitemap schema is working on this structure :






<loc> Location of the page. Don’t forget to write the domain (http://www.domain.com).
<lastmod> When was the page updated the last time (or when was it created). This data is normally recorded in your database by your scripts. You must give this value with a W3C valid format.
<changefreq> What is the frequency of updates for this page? (always, hourly, daily, weekly, monthly, yearly, never). This is only to help Google, Google may not respect this indication. This is useless to set always if you do not plan to update a page once it is created.
<priority>

Priority is a way for Google to know which pages are more important than some others in your website. This comparison doesn’t apply to other websites. It is useless to put 1 everywhere, you won’t help yourself. Give a higher priority to pages that seem more important and that updates often.

If everything is well working, you should be able to see your Sitemap if you try to reach the page sitemap.xml. Check if it is valid, and then submit it to Google.

Bien sûr, il est possible d’améliorer ce script de plusieurs façons. Par exemple, vous pouvez stocker dans vos tables de données, dans une colonne priority, la priorité à donner à chacune des pages. Même chose pour le changefreq.

Of course, it’s possible to upgrade this script in many ways. For instance, you also could store your pages priorities in an additional column. Same thing for changefreq.

It’s of course a lot less complicated with CMS.

Create a dynamic Sitemap for Joomla!

For Joomla!, you have 2 major choices of components :  xMap and Joomap, both available for J!1.0x et J!1.5x versions.

Je n’ai pas essayé Joomap, mais xMap fonctionne très bien. Il existe des extensions pour la plupart des composants connus (Sobi2, Adsmanager, Community Builder, …), ce qui est indispensable. Il s’agit des deux plus connus, mais il existe d’autres composants.

I didn’t try Joomap, but xMap works fine. There are extensions for most of the popular components (Sobi2, Adsmanager, Community Builder, …), which is very important. xMap and Joomap are the most known components, but there are other components you may want to try.

Create a dynamic Sitemap for Drupal

Install the XML Sitemap module for Drupal, disponible pour Drupal 5.x.

Créer un sitemap dynamique pour WordPress

Download the plugin of Arne Brachhold, which works fine. If you are interested into SEO, I invite you to read my article about SEO Ranking with WordPress.

Ce message est également disponible en : French

5 thoughts on “Create a Google Sitemap for your website

  1. AndrewBoldman

    Hi, good post. I have been woondering about this issue,so thanks for posting. I’ll definitely be coming back to your site.

  2. Heike

    I see a lot of interesting content on your blog.
    You have to spend a lot of time writing, i know how to save you a
    lot of work, there is a tool that creates unique, SEO friendly posts in couple of minutes, just type in google
    – laranita’s free content source

  3. zhongweixing

    鲍雁洲日本街头摄影作品Publishedon十 weixingzhong 一月01,2011withNoComments鲍雁洲,中国摄影师,现居日本,他的相册《SnapShot》已有上千张作品,weixingzhong,大多是街头摄影,包括中国和日本,颇具风格并能长期坚持不懈,值得一看。

  4. weixingzhong

    读报Publishedon十月20,2010with1Comment我的个人生活 weixingzhong 已经远离了电视和报纸不是说我两耳不闻窗外事了,而是我的信息来源全部依靠网络老实说,这不是个好习惯,人会变得懒惰例如前阵子的中巴男篮斗殴,在网上看到这则消息,OK,我知道了这么回事,却对事件细节的来龙去脉一概不清,因为我觉得只光看新闻标题就足够了,内容不感兴趣,于是我也就不点击新闻详细内容当然,这完全归咎于个人原因今天看到印象中国对中巴男篮斗殴各家报纸的报道做了个版面集结,有一种非常亲切的感动,从前在大学课堂里,学新闻的同学们都有这样的经验,老师们总让学生做某件新闻事件各媒体的报道对比新闻事件不感兴趣,weixing

Leave a Reply

Your email address will not be published. Required fields are marked *