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.



2 comments:
When I read "MOSS" I was really hoping this post was about The I.T. Crowd.
I've tried this and I can't get it to work with SharePoint. I've tried numerous ISAPI, IIS Rewrite and .Net Rewrite modules none ever work for me with SharePoint. Even if I hard code a value in the config file like redirect from http://site.com/Pages/One.aspx tohttp://site.com/Pages/Two.aspx it doesn't redirect so I know its not my reg expression snytax. When SharePoint does a redirect from http://site.com to http://site.com/Page/default.aspx it throws a 302 not a 301. Search engines don't like this so ever since we moved our external site to Moss 2007 our Search ranks have gone down to zero. It should not be that hard to do a rewrite with SharePoint. MS really dropped the ball on this one. Truely wish we never decieded to use Moss 2007 externally... not the best choice becasue of this one issue that MS can't solve for us.
Post a Comment