Blog
.
SEO-friendly URLs in Sitecore
June 1st, 2010
Application Development, Internet Strategy, Technology, Web Content Management
Search Engine Optimization (SEO) is a critical feature of any Web site. One aspect of SEO is the URL itself – there are certain best practices to follow when it comes to URLs so that they can be best interpreted by search engines, and are built in the best way possible to increase their rankings. When your site is being run by a CMS, you have to make sure that it’s creating SEO-friendly URLs for you.
You’ll notice that the URL of this post is http://blog.navigationarts.com/seo-url-sitecore/, which is an optimized URL. Here are a few rules that it’s following:
- It isn’t unnecessarily long.
- It uses hyphens to separate words.
- The words in the URL are relevant and descriptive of the page’s content.
- It is in lowercase.
- It ends in a slash.
Sitecore CMS, out of the box, doesn’t create URLs in this manner. A URL in Sitecore is reflective of the content tree, and by default adds an ASPX extension. For instance, an Item in Sitecore located in the content tree at /sitecore/content/Home/Our Offerings/User Experience Design would have a URL of http://mysite.com/Our%20Offerings/User%20Experience%20Design.aspx. Note that %20 is the standard internet translation for a space; because spaces are left in the URL, this automatically gets translated. Not only is this URL poorly set up for SEO, it’s hard to read and impossible to memorize.
You can get around some of the problems with this URL by creating item names that are lowercase and have hyphens instead of spaces, but this creates an uglier space for content editors to work in. Even more importantly however, Sitecore allows for fields to default to the Item name (through the use of a default value of “$name”), and this approach makes the use of that feature inappropriate. For example, imagine that a page will display the “title” field of an Item – if the item was created with the name “user-experience-design”, but we wanted “User Experience Design” to appear on the page, we’re going to have some editing to do. In a perfect world, Item names and their corresponding URLs will have the same words, but will adhere to their own conventions around spaces, case, etc.
The first thing that needs to be done is to configure Sitecore such that it doesn’t add the ASPX extension to the URL. The steps for that are outlined here. After that’s done, our URL will be http://mysite.com/Our%20Offerings/User%20Experience%20Design.
The next step is to have spaces be changed to hyphens. In order to do this, we need to edit Sitecore’s web.config and tell it to replace ” ” with “-”. In the “encodeNameReplacements” node, we add the final “replace” node seen below. After this change is in place, our URL becomes http://mysite.com/Our-Offerings/User-Experience-Design.
<encodenamereplacements> <replace mode="on" find="&" replaceWith=",-a-," /> <replace mode="on" find="?" replaceWith=",-q-," /> <replace mode="on" find="/" replaceWith=",-s-," /> <replace mode="on" find="*" replaceWith=",-w-," /> <replace mode="on" find="." replaceWith=",-d-," /> <replace mode="on" find=":" replaceWith=",-c-," /> <replace mode="on" find=" " replaceWith="-" /> </encodenamereplacements>
Because of this change, whenever someone requests a page with a hyphen, Sitecore is going to assume that it needs to be translated to a space – therefore any Items that have hyphens in their names won’t be found. We need to configure Sitecore to not allow content managers to use hyphens in their Item names. In order to do this, we find this line in web.config: <setting name=”InvalidItemNameChars” value=”\/:?”<>|[]/> and change it to <setting name=”InvalidItemNameChars” value=”\/:?”<>|[]-/>.
Now we need to make a decision. Sitecore (as of version 6.1) cannot add a trailing slash to a URL, but it can be extended to do so. John West has developed a module that will put the URL into lowercase and add a “/” at the end; it can be found here. In order for this to work, you add this module (a C#.NET class) to your project, add any modules that it relies on to your project, and make some changes to web.config so that Sitecore knows to use the module for URL construction. This is a little trickier to do than anything else we’ve done so far, and isn’t guaranteed to work as Sitecore is upgraded.
The benefits of having that trailing slash are that it gives a slight boost to SEO, and it hides the implementation of your website – http://mysite.com/Our-Offerings/User-Experience-Design/ could be an Item in Sitecore, a folder that contains index.html, default.php, a .jsp file, or anything else. When the implementation of a site is hidden, you can change languages that the page is written in without losing any SEO rankings. Additionally, if you have a site that has mixed implementations, this can be completely hidden from users.
If you decide that the trailing slash just isn’t worth it, then we’re going to need to make another change to web.config to tell it to make our URL lowercase. In the same section that we told Sitecore to translate spaces into hyphens, we’re now going to tell it to translate “A” into “a”, “B” into “b”, etc. It’s not an elegant solution, but it’s reliable, and doesn’t create require the inclusion of any non-supported code. Here’s what we need to add to web.config:
<replace mode="on" find="A" replaceWith="a" /> <replace mode="on" find="B" replaceWith="b" /> ... <replace mode="on" find="Z" replaceWith="z" />
Finally, our URL is either http://mysite.com/our-offerings/user-experience-design or http://mysite.com/our-offerings/user-experience-design/, depending on how daring or prudent you were. Your content managers are now happy, search engines are happy, your users are happy, and by extension you should be happy. Enjoy.
Randall Davis
.
Tags: Dynamic URLs, SEO, Sitecore

2 Responses
Very nice post Randall – based on the demos, I was assuming one could enter a “search engine friendly” URL directly into the page configuration (via dashboard) – is that not a correct assumption?
[...] website generates URLs that only use lowercase letters. In Sitecore, there are various methods (here's one, and another) that you can implement to support [...]