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.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

Archive /

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

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

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


Go to End


4 Posts   5906 Views

Avatar
Tatey

Community Member, 18 Posts

7 April 2008 at 5:30pm

Edited: 09/04/2008 3:11pm

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

Avatar
Tatey

Community Member, 18 Posts

9 April 2008 at 3:16pm

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.

Avatar
Liam

Community Member, 470 Posts

9 April 2008 at 4:09pm

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

Avatar
ScottiouS

Community Member, 54 Posts

9 May 2008 at 12:17pm

Edited: 09/05/2008 1:20pm

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.