Community Server & Redirect of old urls
We’ve been running on .Text for quite a while, but continue to find bugs in it. Especially the fact that randomly, people cannot edit the items they have just placed on their blog is an annoying one.
We are hoping to solve a lot of problems by upgrading to Community Server from Telligent Systems. The reason why we haven’t upgraded in the past, is because of the new location of the pages. Version 1.1 has become more flexible on the location of the community site and I’ve found a very small but excellent component for url rewriting. I’ve done some of the coding myself at first, but with this component I don’t have to reinvent the wheel as it has all functionality I want.
Via Mischa Kroon I’ve found the link to this url rewriting component. It reads settings from your web.config to see what page(s) it has to redirect and whereto. This is very flexible as it also works with regular expressions. For all Community Server junkies or people that are afraid to upgrade (like I was), here’s what I did.
Remember, these instructions are for CS 1.1 but should work anywhere.
I’ll first explain the current and new situations. In the current situation, the url is like bloggingabout.net/username/ whereas the new situation will be bloggingabout.net/blogs/username/. There are a lot of possible directories and files behind those urls, so it should definitly be solved by a regular expression. Here’s how I did it.
First, download the component, unzip it and in the directory /demo/bin/ you can find two .dll files. Copy those to the /bin/ directory on your website.
Now you have to edit your web.config and you are done! First, find the <httpmodules> tag. If you haven’t added anything, make it look like this.
2: <add name="RedirectModule" type="Madgeek.Web.RedirectModule, Madgeek.RedirectModule" />
3: <add name="CommunityServer" type="CommunityServer.CSHttpModule, CommunityServer.Components" />
4: <add name="Profile" type="Microsoft.ScalableHosting.Profile.ProfileModule, MemberRole (...) 7562"/>
5: <add name="RoleManager" type="Microsoft.ScalableHosting.Security.RoleManagerModule, M (...) 7562" />
At line 2 you can see the line I added. I’ve truncated some of the content (in line 4 and 5) so it won’t be that long.
Now you add another line to your configSections.
2: <sectionGroup name="memberrolesprototype">
3: <section name="membership" type="Microsoft.ScalableH (...) 7562"/>
4: <section name="roleManager" type="Microsoft.ScalablH (...) 7562"/>
5: <section name="profile" type="Microsoft.ScalableHost (...) 7562"/>
6: <section name="anonymousIdentification" type="Micros (...) 7562"/>
8: <section name="redirections" type="Madgeek.Configuration.XmlSerializerSectionHandler, Madgeek.RedirectModule" />
This time you can see the added section at line 8.
Now all you have to do is add your redirection part. Mine looks like this:
1: <redirections type="Madgeek.Web.ConfigRedirections, Madgeek.RedirectModule">
2: <add permanent="true" ignoreCase="true" targetUrl="^/MainFeed.aspx" destinationUrl="/blogs/MainFeed.aspx" />
3: <add permanent="true" ignoreCase="true" targetUrl="^/(dennis|rj|patrick)/(.*).aspx??(.*)" destinationUrl="~/blogs/$1/$2.aspx" />
In line two the main rss feed is redirected to the new location. This only concerns one file and is, as it looks, very easy. But now the current blogs to their new location. The third line tells that it should look for directories starting with either dennis, rj, or patrick and forward those to the destination url. I will have to include all bloggers currently in our community in the final version though. The regex will place the found user-directory at the $1 location and the complete directory structure after that and the file behind it at the $2 location. It should forward every .aspx file.
You can also see the parameter permanent which is set to true. This will make the component send an error 303. This tells the search engines like Google that it’s a permanent move of the file. The search engine will then update its index, which was very important for us.
I’ll do some additional tests soon and hope to be able to upgrade BloggingAbout.NET without any problems.