URL redirection or URL mapping in Sharepoint

7. August 2008

URL redirection in sharepoint can be done with many different ways, but the one I have most useful is to implement it via httpmodule.
Just use following piece of code to create httpmodule and update web.config of the web application to add that module entry and everything will work fine:

namespace BWL.RedirectModule
{
    public class Redirector : IHttpModule
    {
        public void Dispose()        { }        
        public void Init(HttpApplication context)       
        {
            context.BeginRequest +=new EventHandler(context_BeginRequest);
        }        
        void context_BeginRequest(object sender, EventArgs e)
        {      
            string domain = @"(beyond)(weblog|weblogs)(.com/*$)"; //specify your URL here to be checked for redirection
            HttpApplication app = (HttpApplication)sender;
            string requestUrl = app.Request.Url.ToString(); 

            if(Regex.IsMatch(requestUrl,domain))
                app.Response.Redirect("http://beyondweblogs.com/sites/bwlportal"); // if url is found, redirect it to the new url
        }        
    }
} 

Compile it as a dll, then copy this dll to the sharepoint web application bin folder. Finally, copy following line in the web application's web.config after <httpModules> <clear />

<add name="Redirector" type="BWL.RedirectModule.Redirector" />

enJoy!

SharePoint

Comments

5/18/2010 10:03:20 AM #
Thanks for such a cool blog. Working in community services kind of sucks sometimes. I hate finding sites that just have zero info, jobcommunity in Australia i like the only one i've really visited that is any good.
6/4/2010 11:52:06 PM #
This is a very exciting post, I was looking for this info. Just so you know I located your webpage when I was searching for blogs like mine, so please check out my site sometime and leave me a comment to let me know what you think.
6/12/2010 4:07:28 AM #
The final FIFA match will be very close!   I give it a flip of a coin in my opinion but good luck to both teams! I should be watching for sure!
6/14/2010 12:16:49 AM #
This year the World Cup should be extremely intense!   I give it a flip of a coin with my opinion but good luck to both soccer teams! I will be watching the entire match!
6/23/2010 3:06:37 PM #
Very worthwhile article.  Your ?nternet site is quickly turning out to be certainly one of my favorite features.
8/12/2010 8:25:08 AM #
Whats Up
You are right about your page URL redirection or URL mapping in Sharepoint. I will certainly be reading your site more.
See ya

Add comment


(Will show your Gravatar icon)

  Country flag

biuquote
  • Comment
  • Preview
Loading