14.11.07

Sharepoint / MOSS url rewriting

For the current project I'm working on I needed to get rid of MOSS' /Pages - the client wants nicer looking URL's.
I came across this project which is really simple to use: UrlRewriter

Installing it in SharePoint is also really simple, especially since UrlRewiter is already signed. Just simply GAC the assembly, and add the following to the web.config:

<configSections>
<section name="rewriter" requirePermission="false" type="Intelligencia.UrlRewriter.Configuration.RewriterConfigurationSectionHandler, Intelligencia.UrlRewriter, Version=2.0.0.6, Culture=neutral, PublicKeyToken=0573f3650687980d" />
</configSections>
<SharePoint>
<SafeControls>
<SafeControl Assembly="Intelligencia.UrlRewriter, Version=2.0.0.6, Culture=neutral, PublicKeyToken=0573f3650687980d" Namespace="Intelligencia.UrlRewriter.Configuration.RewriterConfigurationSectionHandler" TypeName="*" Safe="True">
</SafeControls>
</SharePoint>
<system.web>
<httpModules>
<add type="Intelligencia.UrlRewriter.RewriterHttpModule,Intelligencia.UrlRewriter, Version=2.0.0.6, Culture=neutral, PublicKeyToken=0573f3650687980d" name="UrlRewriter" />
</httpModules>
</system.web>


Finally add this in the configuration section:

<rewriter>
<if url="^((?!/Pages/|/Style%20Library/|/Style Library/|/_layouts/|/).+)*$">
<rewrite to="/Pages/$1" />
</if>
</rewriter>


UrlRewriter uses a regular expressions in order to match and replace the url:
^((?!/Pages/|/Style%20Library/|/Style Library/|/_layouts/|/).+)*$

So this will find all url's that don't start with /Pages/ and add it on.