Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We're retiring the forums!

The SilverStripe forums have passed their heyday. They'll stick around, but will be read only. We'd encourage you to get involved in the community via the following channels instead:

Archive /

Our old forums are still available as a read-only archive.

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo

Google Sitemap

Go to End

11 Posts   9397 Views


121 Posts

25 October 2007 at 1:18am

Here's our code for generating a Google Sitemap (couldn't find anything about this in the archives):


class SiteMap extends SiteTree {
  static $db = array(
  static $has_one = array(
  function SiteTreeList() {
    $pages = DataObject::get("SiteTree", "ShowInSearch = 1");
    return $pages;
class SiteMap_Controller extends ContentController {


<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="">
<% control SiteTreeList %>
<% end_control %>

Rebuild your DB, and then add a new SiteMap page in the site root with a URL of "sitemap" (title and content are not used). Remember to hide it in menus and search on the behaviour tab.

Your sitemap should now be visible as "/sitemap/", but Google doesn't like this as it's a directory so I add a rule to my .htaccess:

# Google SiteMap
RewriteRule sitemap.xml sitemap/ [NC,PT]

RewriteCond %{REQUEST_URI} !(\.gif)|(\.jpg)|(\.png)|(\.css)|(\.js)|(\.php)$

to make it available as "sitemap.xml"

Finally to finish off, you can add a Sitemap line to your robots.txt file to allow search engines to discover your sitemap automatically:

User-agent: *

frederik aka tina

Community Member, 5 Posts

10 December 2007 at 2:11am

Page not found


localhost fred # cat /var/www/localhost/htdocs/cms/.htaccess

RewriteEngine On

RewriteCond %{REQUEST_URI} !(\.gif)|(\.jpg)|(\.png)|(\.css)|(\.js)|(\.php)$ 

RewriteCond %{REQUEST_URI} ^(.*)$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule .* sapphire/main.php?url=%1&%{QUERY_STRING} [L]

# Google SiteMap

RewriteRule sitemap.xml sitemap/ [NC,PT]

RewriteCond %{REQUEST_URI} !(\.gif)|(\.jpg)|(\.png)|(\.css)|(\.js)|(\.php)$



Administrator, 690 Posts

10 December 2007 at 9:08am

2.2.0 includes a Google Sitemap generator out of the box.

The class is sapphire/misc/GoogleSitemap.php

There's a director rule for /sitemap.xml, so you don't need to modify your .htaccess


Community Member, 156 Posts

13 March 2008 at 6:56pm

how can you exclude a page/section from the sitemap but still keep it visible to the public.


Community Member, 791 Posts

11 September 2008 at 12:22am

Edited: 12/09/2008 8:55pm

I'm seeing interesting behavior regarding the generated Google sitemap.xml on a site of a client of mine..

See :

2 problems :
1> Whitespace in front of the XML (validation-problem)
2> All the change-frequencies are set to "always" which Google does not like

Can anyone shed some light on this ?

Update :

Created a ticket :


Community Member, 7 Posts

26 September 2008 at 6:39pm

Hi, how do you enable sitemap.xml? I thought it was supposed to be 'out the box' but I get page not found, or if I have a page named 'sitemap' then I get that instead.

Here is an example:




Community Member, 791 Posts

26 September 2008 at 7:08pm

Edited: 26/09/2008 7:08pm

Hmmm... as far as I know , it _is_ out of the box.

Make sure not to create a Google sitemap class yourself since it is already included in Sapphire... (sapphire's main.php adds a rule which maps the sitemap.xml url to the GoogleSitemap Class)....


Community Member, 7 Posts

26 September 2008 at 10:13pm

Ok, did some digging and it seems the rule is not working:

'sitemap.xml' => 'GoogleSitemap' within sapphire/_config.php

If I change the rule to something without the .xml extension it works, but any name with .xml in fails.

It seems rules do now like '.' in them, so how could this ever work I wonder?

Go to Top