Jump to:

17452 Posts in 4473 Topics by 1971 members

Archive

SilverStripe Forums » Archive » SEO Optimisation: 301 redirects, non-trailing slashes and /home

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

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

Page: 1
Go to End
Author Topic: 4680 Views
  • Tatey
    Avatar
    Community Member
    18 Posts

    SEO Optimisation: 301 redirects, non-trailing slashes and /home Link to this post

    In the recent months, Fabie and I have been seeking for an unobtrusive mechanism to further optimise SilverStripe based installations for search engines.

    That is, pages with a trailing slash and pages without a trailing slash are accessible to search engine crawlers. While this isn't necessarily an issue for humans, it essentially creates two independent pages with identical content; resulting in various negative implications for search engines.

    The phenomena is known as Canonical URLs.

    Fortunately, a developer from Fontis IT consulting and T3hDuk have been able to formulate a suitable work-around that takes advantage of Apache's mod_rewrite functionality. That is, it doesn't touch the Sapphire core at all!

    I thought it would be appropriate to share with everyone, in case other developers feel that they are in a similar position to me.

    * Adds a trailing slash to URLs without a trailing slash
    * Capability to redirect requests without the WWW to include the WWW
    * Correct the /home 302 redirect
    * All redirects are 301

    http://pastie.caboo.se/177666

  • Tatey
    Avatar
    Community Member
    18 Posts

    Re: SEO Optimisation: 301 redirects, non-trailing slashes and /home Link to this post

    Discovered a problem where files could not be uploaded using the "Files & Images" section of the CMS. I've modified the rewrite rules to exclude /admin. The "pastie" in my previous post has already been updated.

  • Liam
    Avatar
    Community Member
    470 Posts

    Re: SEO Optimisation: 301 redirects, non-trailing slashes and /home Link to this post

    If you're using -rc2 it's a known bug and not your modifications fault.

  • ScottiouS
    Avatar
    Community Member
    54 Posts

    Re: SEO Optimisation: 301 redirects, non-trailing slashes and /home Link to this post

    That's great Tatey, was exactly what I needed.

    I have a suggestion:

    Change:
    RewriteCond %{HTTP_HOST} ^domain\.com.\au [NC]

    to:
    RewriteCond %{HTTP_HOST} ^domain\.com.\au$ [NC]

    This way you will then capture domain.com.au/somepage/ which will rewrite with the www.

    .. and you may wish to change this line also to include other common file types otherwise these files won't be found due to the rewrite adding a / at the end.

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

    to:
    RewriteCond %{REQUEST_URI} !(\.gif)|(\.jpg)|(\.png)|(\.css)|(\.js)|(\.php)|(\.flv)|(\.swf)|(\.html)|(\.htm)$

    Or simply make is include any other file types you need to be detected.

    4680 Views
Page: 1
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.