IIS7 Extensionless Urls and Kentico CMS 5.0
Posted by: admin | Technical | 29.01.2010
This post has been updated and is a wee bit out of date, see here for the updated version:
http://www.markerstudio.com/technical/2010/03/iis7-extensionless-urls-seo-and-kentico-5–0/
Base System Requirements: IIS 7.0 with .net 3.5 SP1 on a Windows Vista dev machine or Windows 2008 server to utilise extensionless urls.
Firstly, install the marvellous IIS 7.0 URL Rewrite Module
Get it here: http://www.iis.net/downloads/default.aspx?tabid=34&g=6&i=1692
Learn about it here: http://learn.iis.net/page.aspx/460/using-url-rewrite-module/
Now, all you have to do is tell Kentico not to use extensions on postback urls. I had to delve into the actual source code to locate this little gem of a setting. Set it to false and stick in AppSettings.config to ensure Kentico will not write out form actions which end in .aspx.
CMSUseExtensionOnPostback = false
Next, make sure Kentico is configured to not add friendly url extensions when it generates urls.
- Site Manager > Settings > Urls>
- Ensure the Friendly Url Extensions value is blank
Now all you need to do now is apply the rewriting rules within the web.config, utilising the IIS Rewrite Module’s capabilities. (Note that you don’t need to do anything within IIS, you can manage everything within the web.config and simply deploy it out to target servers without worrying about any additional configuration).
For example, the EnforceTrailingSlash rule below will ensure that a trailing slash is added to all urls without extensions, performing a 301 redirect in the process. This is so to avoid multiple urls (ones with and without slashes) returning the same content which isn’t ideal from an SEO perspective.
The TrailingSlashToAspx rule below will ensure that a trailing slash is rewritten internally to .aspx, so that the kentico rewriting engine can take over. Note that the Kentico CMS folders are ignored (ones starting with CMS..)
<system.webServer>
<rewrite>
<rules>
<rule name=”EnforceTrailingSlash”>
<match url=”^(.*)$” ignoreCase=”false” />
<conditions>
<add input=”{REQUEST_FILENAME}” matchType=”IsFile” negate=”true” />
<add input=”{REQUEST_URI}” negate=”true” pattern=”(.*)\.([a-zA-Z]+)(/.*)?$” />
<add input=”{REQUEST_URI}” negate=”true” pattern=”(.*)\.([a-zA-Z]+)(\?.*)?$” />
<add input=”{REQUEST_URI}” negate=“true” pattern=”(.*)/(\?.*)?$”/>
</conditions>
<action type=”Redirect” url=”{R:1}/” redirectType=”Permanent” />
</rule>
<rule name=”TrailingSlashToAspx”>
<match url=”^(.*)/$” />
<conditions>
<add input=”{REQUEST_FILENAME}” matchType=”IsFile” negate=”true” />
<add input=”{REQUEST_URI}” negate=”true” pattern=”/cms(.*)$” />
<add input=”{REQUEST_URI}” negate=“true” pattern=”/getattachment/(.*)$”/>
<add input=”{REQUEST_URI}” negate=“true” pattern=”/getfile/(.*)$”/>
</conditions>
<action type=”Rewrite” url=”{R:1}.aspx” />
</rule>
</rules>
</rewrite>
</system.webServer>
And so there you have it, a relatively painless way to get yourself all SEOd with IIS 7.0 and Kentico CMS 5.0.
So what about the Kentico 5.0 SEO Features? mmm…maybe not
Kentico makes available 2 settings in v5.0 which are “Always apply trailing slash to urls” and “Always lower case url names” which in theory sound great, but i still recommend the above approach for control.
The first one only really makes sense if you are using extensionless urls anyway (which you need to configure separately from this setting, see below). When you set “Always apply trailing slash to urls” this ensures all urls generated by Kentico end with a trailing slash, which is a good thing. However, it also means that Kentico will attempt to add a trailing slash to our rewritten url above!
When this happens you get an infinite loop occuring where the rewrite module is attempting to rewrite the url to .aspx for Kentico to process and for some reason (and this is clearly in my view a bug) Kentico is attempting to put a trailing slash on a rewritten url which ends in an aspx. Kentico should IMHO leave this already rewritten url alone and only apply 301s and trailing slashes if the url actually requires it.
We’re still therefore waiting on a solution that just has Kentico generate all urls with trailing slashes and nothing else!
Upon investigation with support, Kentico still appear to recommend that you use the old IIS 6.x approach of assigning custom 404 error page to a Kentico handler page in order to implement extensionless urls. If you are using IIS 6, by all means use this approach if you must, but i don’t really like the extra configuration effort and it’s always felt a bit hacky to do this. 404 errors should be generated when a page is actually not found. This older approach is obviously not compatible with what i’m suggesting above.
Another problem we discovered with the Kentico SEO settings was when used in combination with aliasing. Aliasing is a Kentico feature wherby you can specifiy a url such as /articles/{article-title}, where {article-title} is any piece of text (the alias) and that these alias url requests all point to some underlying url such as /articles/article/.
If you switch on the “Always lower case url names” and you request a dynamic alias such as /articles/MY-ARTICLE/ it will redirect to the underlying url /articles/article/ breaking the aliasing approach. This appear to be a core bug in kentico 5.0.

Hi, as mentioned by our CTO in his comment to your comment on CTO’s blog, the two first issues are caused by the fact that we are still supporting older systems :-(. The last issue with aliasing — I think I was able to reproduce it so I passed it to our developers to take a look. I hope they will be able to fix it soon. Thank you.
Best Regards,
Juraj Ondrus
Kentico