Sitemap

Contents...

Sitemap file is an XML file containing information for search engines' crawlers on the website pages, which are available for indexing. Read more about the file format at http://www.sitemaps.org/protocol.html

Webasyst framework automatically generates the main sitemap.xml file, which a sitemap index file (read more about sitemap index files at http://www.sitemaps.org/protocol.html#sitemapIndexXMLExample). This file contains the URLs of sitemap files of specific applications; e.g., sitemap-blog.xml, sitemap-site.xml:

<?xml version="1.0" encoding="UTF-8"?>
<sitemapindex xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
  xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/siteindex.xsd" 
  xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
<sitemap>
     <loc>http://www.webasyst.com/sitemap-blog.xml</loc>
     <lastmod>2012-06-07T16:49:08+04:00</lastmod>
</sitemap>
<sitemap>
      <loc>http://www.webasyst.com/sitemap-site.xml</loc>
      <lastmod>2012-06-07T16:49:08+04:00</lastmod>
</sitemap>
</sitemapindex>

In this sitemap index are automatically included all applications, which have a frontend (frontend => true), which are settled in the routing settings if the current website, and which can generate sitemap files (all these three conditions must be satisfied). For the latter condition (i.e. to enable the generation of sitemap file sitemap-APP_ID.xml), it is necessary to create file wa-apps/APP_ID/lib/config/APP_IDSitemapConfig.class.php.

For example, if your application testapp can display different web pages on different domain names (a simple CMS), then generation of file APP_IDSitemapConfig.class.php for this application can be implemented as shown below:

<?php

// wa-apps/testapp/lib/config/testappSitemapConfig.class.php
class testappSitemapConfig extends waSitemapConfig
{

    public function execute()
    {
        // Get the page list of current domain name $this->domain
        $model = new testappPageModel();
        $pages = $model->getPages($this->domain);
        // Get all settlements of this application for the current domain name
        $routes = $this->getRoutes();
        foreach ($routes as $route) {
            // Generating a part of the page URL, which is specified in the application's routing settings.
	        // For example, if the application is for domain name domain.com is settled at /testapp/*, then this function will return http://domain.com/testapp/
            $route_url = $this->getUrlByRoute($route);
            foreach ($pages as $p) {
                // Adding URL to sitemap
  		        $this->addUrl($route_url.$p['url'], $p['update_datetime'], self::CHANGE_MONTHLY, 0.8);
            }
        }
    }

}

The main function used for adding an element to the sitemap file is addUrl($url, $last_modified_time, $changefreq, $priority), which accepts the following parameters:

  • $url: absolute page URL
  • $last_modified_time: last page modification time
  • $changefreq: page modification frequency; e.g., weekly, monthly
  • $priority: page priority from 0 to 1