EPiServer has great functionality for managing SEO friendly URLs where the user can effectively manage their own URL structure such as:
In most cases this works really well. However I was recently working with SEO consultant David Deutsch on a project where search engine rankings are paramount to the success of the business. His requirement was to have reallyfriendly URLs for SEO purposes.
Using the example above he wanted:
http://www.mysite.com/Latest-World-Football-News/ instead of http://www.mysite.com/news/.
It could be argued that we could simply change the URL segment and be done. However the keywords needed to appear in the URL, only for the current page whilst still maintaining a hierarchy of child pages. For example he also wanted the following pages to be valid:
- http://www.mysite.com/news/European-Football-News/ instead of http://www.mysite.com/news/europe
- http://www.mysite.com/news/europe/Football-News-For-The-UK/ instead of http://www.mysite.com/news/europe/uk
- http://www.mysite.com/news/europe/uk/Liverpool-FC-News/ instead of http://www.mysite.com/news/europe/uk/liverpool
and so on…
There are good SEO reasons for this as we don't want keywords from a parent page polluting the keywords on a child page. In the example given "European Football News" are the keywords on the Europe news page but keywords on the ultimate child page may be "Liverpool FC News" which aren't really related to the parent keywords. (Also as a side note, as developers we don't really want really really long URLs).
So it can be seen that any page needs to effectively have two URL segments, one for SEO purposes and one for serving children pages. This is pretty easily achieved as follows:
- Add a "SEO URL segment" to each page type that we want to use it
- Create a custom URL rewriter based on the standard friendly URL rewriter (see below)
- Use the SEO friendly URL rewriter in place of the standard friendly URL rewriter
This code overrides the ConvertToInternal and ConvertToExternal methods of the EPiServer FriendlyUrlRewriteProvider and creates a new "SEOFriendlyURLRewriter":
This looks for a really friendly SEO property and uses that in place of the URL segment if its specified. Obviously this needs to be plugged into episerver.config as follows:
However this isn't the end of the story. If someone was browsing to http://www.mysite.com/news/europe/Football-News-For-The-UK/ then removed the "Latest-Football-News-UK" segment then EPiServer will serve http://www.mysite.com/news/europe/ quite happily. However we don't really want this as if the link was ever used then Google could penalise the site for having duplicate content. So this drives the requirement to automatically 301 redirect to the really SEO friendly name. This is achieved with a page plug in as follows:
This code is designed to show a concept is not production ready (there is no error handling or logging for a start). Use at your own risk.
This is a simple change that allows SEO experts to specify as many keywords as they like in the URL for particular page. While it feels a little odd to have a URL structure that's not perfectly logical it allows the SEO guys to get exactly the structure they want/need. Ultimately this should drive traffic to your site and keep your SEO guys very happy.
Note: The project we worked on wasn't for a football site!