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.

18 comments:

Graham said...

When I read "MOSS" I was really hoping this post was about The I.T. Crowd.

Anonymous said...

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.

Rik Locke said...

I've set this up as described but I'm getting "Unrecognized configuration section rewriter."
from the web.config.
Any ideas?

jvancojr said...

What do you mean 'configuration section'?

greenerist said...

Don't you have to close the SafeControl tag? Also i can't seem to get it to rewrite this "www.domain.com/usa" to "www.domain-usa.com"

any ideas?

Hardik said...

Doesn't work for me too... I need to strip /pages from URL. Can you please help me???

Chad Schultz said...

Wanted to let you know that the SafeControls line is wrong. It does not have a closing tag. Should look like this.

<SafeControl Assembly="Intelligencia.UrlRewriter, Version=2.0.0.6, Culture=neutral, PublicKeyToken=0573f3650687980d" Namespace="Intelligencia.UrlRewriter.Configuration.RewriterConfigurationSectionHandler" TypeName="*" Safe="True" />

You will get a server 500 error if the closing tag is missing.

tom tajic said...

I've followed your instructions.
- I've put the UrlRewriter to GAC.
- I've corrected the missing /> at SafeControl element.
- I've left rewriter configuration element empty (just to see it working
- I've succesfully set up an ordinary (not MOSS) asp.net site with UrlRewriter

I get the following error

Event code: 3005
Event message: An unhandled exception has occurred.
Event time: 3/2/2009 4:00:17 PM
Event time (UTC): 3/2/2009 3:00:17 PM
Event ID: d2828ca1270748d19e058ad97b87f8c4
Event sequence: 2
Event occurrence: 1
Event detail code: 0

Application information:
Application domain: /LM/W3SVC/1044122875/Root-2-128804796175360000
Trust level: Full
Application Virtual Path: /
Application Path: C:\Inetpub\wwwroot\wss\VirtualDirectories\1407\
Machine name: VM-DEMO-MOSSISO

Process information:
Process ID: 6156
Process name: w3wp.exe
Account name: NT AUTHORITY\NETWORK SERVICE

Exception information:
Exception type: TypeInitializationException
Exception message: The type initializer for 'Intelligencia.UrlRewriter.RewriterHttpModule' threw an exception.

Request information:
Request URL: http://vm-demo-mossiso:1407/_vti_bin/sitedata.asmx
Request path: /_vti_bin/sitedata.asmx
User host address: 192.168.245.140
User:
Is authenticated: False
Authentication Type:
Thread account name: NT AUTHORITY\NETWORK SERVICE

Thread information:
Thread ID: 5
Thread account name: NT AUTHORITY\NETWORK SERVICE
Is impersonating: False
Stack trace:

I've ran out of ideas.

please help?

Anonymous said...

Just wondering: does this work for the 64-bit version of MOSS? Thanks.

Anonymous said...

I have two web app, one for admin with windows authentication and the other one for public users with forms authentication and it is anonymous. i just want that when it shows default.aspx in url i want to hide that extension, it should only show say http://Portal:1212/About/

instead of http://Portal:1212/About/Default.aspx this.
I googled a lot but of no use.Finally i got this dll, i hv copied it to moss server assembly folder, and changed the respective 3 web.config 1.Central admin's config file, 2.Admin Web app config file 3.Public Facing Web app config file.

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

    </SafeControls>

 <httpModules>
<add name="UrlRewriter" type="Intelligencia.UrlRewriter.RewriterHttpModule, Intelligencia.UrlRewriter"/>

    </httpModules>
<system.webServer>
    <modules runAllManagedModulesForAllRequests="true">
      <add name="UrlRewriter" type="Intelligencia.UrlRewriter.RewriterHttpModule"/>
    </modules>
    <validation validateIntegratedModeConfiguration="false"/>
  </system.webServer>
<rewriter>
    <rewrite url="~/Default.aspx" to=" "/>
  </rewriter>
It shows Error: Unrecognized configuration section rewriter.
 in all three applications.
any proper guidence is apprci'te

Fangliang said...

could anybody tell me, which web.config should be modified? The individual website web.config, e.g. "C:\inetpub\wwwroot\...\80\web.config", or the web.config is somewhere eles?

I have modified the web.config for the port 80. But if I open the sharepoint webpage with port 80, the changes in the web.config does not take any effect.

Coul anybody help? Thanks a lot!

Anonymous said...

does not work for me.. i want to remove the /pages from url.. please can u give me the proper regular expression.

thanks.

Anonymous said...

does not work for me.. i want to remove the /pages from url.. please can u give me the proper regular expression.

thanks.

Anonymous said...

Confirm this doesn't work !!

Term Papers said...

I have been visiting various blogs for my term papers writing research. I have found your blog to be quite useful. Keep updating your blog with valuable information... Regards

amar dave said...

Hi
I tried to apply as mentioned to my sharepoint website. But as soon as i add the httpmodule tage to the web.config I get runtime error and website stops working. Can anyone please help me

dan rogy said...

My current project requires ability to display choice column value via color or image associated with a choice

But Sharepoint standard packaged misses that control

I am looking for available solutions on market

I came across

http://amazepoint.com/Products/VisualChoiceColumn/Overview.aspx>

Does anybody has experiece using it?

RK said...

Thank u very much.. Your post had solved a sharepoint problem for me