Jump to:

17452 Posts in 4473 Topics by 1971 members

Archive

SilverStripe Forums » Archive » Google Sitemap

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

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

Page: 1 2
Go to End
Author Topic: 8454 Views
  • jam13
    Avatar
    121 Posts

    Google Sitemap Link to this post

    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

  • frederik aka tina
    Avatar
    Community Member
    5 Posts

    Re: Google Sitemap Link to this post

    http://fredsite.hopto.org/cms/sitemap.xml

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

    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 ###

  • Sam
    Avatar
    Administrator
    679 Posts

    Re: Google Sitemap Link to this post

    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

  • Blackdog
    Avatar
    Community Member
    156 Posts

    Re: Google Sitemap Link to this post

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

  • Fuzz10
    Avatar
    Community Member
    787 Posts

    Re: Google Sitemap Link to this post

    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

  • mallbeury
    Avatar
    Community Member
    7 Posts

    Re: Google Sitemap Link to this post

    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

  • Fuzz10
    Avatar
    Community Member
    787 Posts

    Re: Google Sitemap Link to this post

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

  • mallbeury
    Avatar
    Community Member
    7 Posts

    Re: Google Sitemap Link to this post

    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?

    8454 Views
Page: 1 2
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.