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.

Archive /

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

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

Google Sitemap


Go to End
Reply


11 Posts   8655 Views

Avatar
jam13

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):

code/SiteMap.php:

<?
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 {
}
?>

templates/SiteMap.ss:

<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
<% control SiteTreeList %>
<url>
<loc>$AbsoluteLink</loc>
</url>
<% end_control %>
</urlset>

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: *
Disallow:
Sitemap: http://www.examplesite.com/sitemap.xml

Avatar
frederik aka tina

Community Member, 5 Posts

10 December 2007 at 2:11am

[url]http://fredsite.hopto.org/cms/sitemap.xml[/url]

Page not found
[url]http://fredsite.hopto.org/cms/sitemap[/url]

works...

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

### SILVERSTRIPE START ###
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)$

### SILVERSTRIPE END ###

Avatar
Sam

Administrator, 685 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

Avatar
Blackdog

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.

Avatar
Fuzz10

Community Member, 787 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 : www.fahrenheitstore.nl/sitemap.xml

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 :
http://open.silverstripe.com/ticket/2799

Avatar
mallbeury

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: http://axehomeloans.com.au.s48901.gridserver.com/sitemap.xml

Thanks

Matt

Avatar
Fuzz10

Community Member, 787 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)....

Avatar
mallbeury

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