Google Sitemap and CodeIgniter

About Google Sitemap

Google Sitemap (with the capital S) is a XML file which contains info about pages of your website. As Google said:

Creating and submitting a Sitemap helps make sure that Google knows about all the pages on your site, including URLs that may not be discoverable by Google’s normal crawling process.Google Webmaster help

There is many ways to create your Sitemap before submit it. I’ll introduce some of them in this post.

Do it by your hand …

This is the most directly way to create a Sitemap. Because a Sitemap is just a XML file, you can edit it by your favorite text editor. A general structure of a Sitemap is described as the follwing table:

Sitemap tag definitions
<urlset>RequiredEncloses all information about the set of URLs included in the Sitemap.
<url>RequiredEncloses all information about a specific URL.
<loc>RequiredSpecifies the URL. For images and video, specifies the landing page (aka play page, referrer page). Must be a unique URL.
<lastmod>OptionalThe date the URL was last modifed, in YYYY-MM-DDThh:mmTZD format (time value is optional).
<changefreq>OptionalProvides a hint about how frequently the page is likely to change. Valid values are:

  • always. Use for pages that change every time they are accessed.
  • hourly
  • daily
  • weekly
  • monthly
  • yearly
  • never. Use this value for archived URLs.
<priority>OptionalDescribes the priority of a URL relative to all the other URLs on the site. This priority can range from 1.0 (extremely important) to 0.1 (not important at all).Does not affect your site’s ranking in Google search results. Because this value is relative to other pages on your site, assigning a high priority (or specifying the same priority for all URLs) will not help your site’s search ranking. In addition, setting all pages to the same priority will have no effect.

see more on Google’s page

You can try, but, in my opinion, there are many esier solutions for your task.

Using free online tool

I have found a good free online tool to generate your Sitemap if your site has less than 500 pages, At the time I write this post, the input form is just simple like this:

Fill in the form, click Start and wait for the result. So simple, huh? In the case that you have a “giant” site with thousands of page, …search for a new tool.

Either using tools or your hands, after you have created a XML file, you must upload it to your host before give Google your Sitemap URL. I recommend uploading the Sitemap to a sub folder instead of your root directory. Perhaps you have to modify the .htaccess file to allow people (and of course, Google) to read the XML file.

Dynamically create Sitemap with Codeigniter

For those whose uses Codeigniter, you can easily genarate your sitemap with the Google Sitemaps Plugin at (thanks CI fans). The process of using this library is described so clearly. I think you can follow these steps easily.

Besides using the google_sitemap class as above, I suggest another way. First, create a controller like this:

class sitemap extends CI_Controller {
    function __construct() {

    function index()

As you can see, we just call a view in this controller. In the sitemap view, generate the content of your XML file. Finnaly, submit the following address to Google Webmaster sitemap page:


Leave a Reply

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