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


Reply


6 Posts   2117 Views

Avatar
jam13

121 Posts

25 October 2007 at 5:22am

I posted this in the Contributions forum, but I just realised that it's obsolete so I'm reposting it here as it seems the most appropriate place.

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
Sigurd

Forum Moderator, 628 Posts

25 October 2007 at 9:44pm

Edited: 25/10/2007 9:47pm

Thanks for this, although we'd prefer you add it to trac, so they're more itemised.

Unfortunately SilverStripe 2.2 will have support for sitemaps already thanks to Will Scott's work a few months ago. His work provides some additional features, but its awesome to see how short the code is for the XML sitemap to be produced by you.

PS, love your showcase sites; you might find them being showcased more :)

Avatar
jam13

121 Posts

26 October 2007 at 3:31am


Thanks for this, although we'd prefer you add it to trac, so they're more itemised.

You mean the bug tracker?


Unfortunately SilverStripe 2.2 will have support for sitemaps already thanks to Will Scott's work a few months ago. His work provides some additional features, but its awesome to see how short the code is for the XML sitemap to be produced by you.

Never mind - only took me a couple of hours to work out :)

I wonder if there are any other things in the 2.2 branch that I'm thinking of implementing myself... Is there a definitive changelog yet? Fixing the 404 problem is pretty high up on my list at the moment.


PS, love your showcase sites; you might find them being showcased more :)

Thanks, I shall pass your compliments on to the designers. I noticed you already put the British Potato Council site in your mailshot!

Avatar
KatB

Community Member, 94 Posts

14 April 2008 at 2:19pm

Is there any documentation for the Google Sitemap extension?

I already had a static Sitemap that I left up. Did that interfere with the automatically generated Silverstripe Search Engine Sitemap? When a Search Engine bot comes along, does it receive the Silverstripe version or the static version?

Avatar
Liam

Community Member, 470 Posts

14 April 2008 at 3:29pm

It would view the static file, since it's the real thing. Just type in the address to it yourself and double check.

Avatar
Matt Hardwick

Community Member, 61 Posts

18 August 2008 at 3:41pm

is there anyway to add to the generated sitemap?