Deze pagina is niet beschikbaar in het Nederlands en daarom wordt de Engelse versie van het artikel getoond. Dit komt vooral voor bij technische artikelen.
Every Sitecore project has at least one specification in common: URL's need to be SEO-friendly.
The URL of an item in Sitecore is generated based on its name or display name, depending on the configuration of the LinkProvider.
However, when the (display)name contains spaces or non-alphanumeric characters, this is reflected in the URL.
So an item with path /About Us/How we make $$$ ! will also get those spaces and non-alphanumeric that URL.
We can configure the lowercaseUrls attribute on the LinkProvider, which will get rid of the uppercase characters, but the spaces will still be there.
ParTech has created a module to solve this problem and has used it in several of their projects.
Our module provides you with two (mutually exclusive) solutions:
- Generate links without spaces or weird characters, they are replaced by hyphens (-)
So the item "How we make $$$ !" will get the URL "how-we-make------"
- Add a new ItemResolver that can resolve items by their SEO-friendly URL
So the URL "how-we-make------" can be resolved to the item "How we make $$$ !"
How does it work?
Links are generated using a custom LinkProvider.
Once installed, you can use Sitecore.Links.LinkManager.GetItemUrl() to retrieve the friendly URL of an item (as you would always do).
This needs no further explanation (if it does, just let me know).
The ItemResolver is a little more interesting, because how can you convert a URL like "how-we-make------" back to the display name "How we make $$$ !"?
This is done by traversing the tree for each part of the URL.
Let's take this URL as an example: "/about-us/how-we-make------"
First we split the URL on the slash character so we get the item hierarchy.
The result will be two items: "about-us" and "how-we-make------".
Then we search the root of our site (in this case the Home item) for children and normalize each child's (display)name like we do in our LinkProvider.
So when we encounter "About Us" it will be normalized to "about-us" and we can match it with our URL.
Once we have matched the first item in the hierarchy, we continue with its children and find a match for the next item in the hierarchy.
So we would eventually encounter "How we make $$$ !", normalize it to "how-we-make------" and be able to match it with the URL.
As long as your site is developed using Sitecore's guidelines for maximum child count (you don't want to have more than 100 children directly underneath one item), this method will perform perfectly.
If your hierarchy goes too deep (>15 levels) it will obviously slow down the performance of this module.
Installation and configuration
Installing the module will make no modifications to your Sitecore databases, it only adds one DLL file and a .config file to configure the module.
The configuration file sets up the ItemResolver and LinkProvider.
The LinkProvider can be configured in the same way as Sitecore's default provider, with the addition of a few attributes:
Apply the linkprovider ONLY to for sites that are listed here.
The sites are identified by their sitename as configured in the <site> element and must be comma separated.
Don't apply the linkprovider to the sites that are listed here.
The sites are identified in the same way as for the applyForSites attribute.
If its value is "true", all requests to items that are made without the friendly URL are 301-redirected to the corresponding friendly URL.
All these configuration attributes are optional, although it's highly recommended you leave at least the default value (shell,login,admin) for ignoreForSites in there to prevent the Sitecore admin from breaking.
It's also recommended the you leave forceFriendlyUrl set to true, because you don't want your items to be accessible using multiple URL's.
The module is available on GitHub: https://github.com/ParTech/Seo-Friendly-Url.
If you want to download the Sitecore installation package directly, you can grab it here: https://github.com/ParTech/Seo-Friendly-Url/raw/master/Release/ParTech.Modules.SeoUrl-1.0.2.zip.
It will also be added to the Marketplace in the next few days.
This module is tested with Sitecore 6.5, 6.6 and 7.0 and should work fine with older versions like 6.3 or 6.4