17488 Posts in 4473 Topics by 1978 members
| Go to End | Next > | |
| Author | Topic: | 8025 Views |
-
Google Sitemap

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 -
Re: Google Sitemap

10 December 2007 at 2:11am
http://fredsite.hopto.org/cms/sitemap.xml
Page not found
http://fredsite.hopto.org/cms/sitemapworks...
localhost fred # cat /var/www/localhost/htdocs/cms/.htaccess
### SILVERSTRIPE START ###
RewriteEngine OnRewriteCond %{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 ###
-
Re: Google Sitemap

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
-
Re: Google Sitemap

13 March 2008 at 6:56pm
how can you exclude a page/section from the sitemap but still keep it visible to the public.
-
Re: Google Sitemap

11 September 2008 at 12:22am Last edited: 12 September 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 likeCan anyone shed some light on this ?
Update :
Created a ticket :
http://open.silverstripe.com/ticket/2799 -
Re: Google Sitemap

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
-
Re: Google Sitemap

26 September 2008 at 7:08pm Last edited: 26 September 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)....
-
Re: Google Sitemap

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?
| 8025 Views | ||
| Go to Top | Next > |





