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.


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

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

SEO Optimisation: 301 redirects, non-trailing slashes and /home


4 Posts   4792 Views


7 April 2008 at 5:30pm (Last edited: 9 April 2008 3:11pm), Community Member, 18 Posts

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 [url=]Canonical URLs[/url].

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


9 April 2008 at 3:16pm Community Member, 18 Posts

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.


9 April 2008 at 4:09pm Community Member, 470 Posts

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


9 May 2008 at 12:17pm (Last edited: 9 May 2008 1:20pm), Community Member, 54 Posts

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

I have a suggestion:

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

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

This way you will then capture 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.

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

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.