views:

137

answers:

5

Hi all:

I want to add the ability to redirect users when they visit certain old sites. The URL of the old sites are unknown, but the server name is the same, e.g.

Old site url:

http://sharepoint/mySite/default.aspx

New site url:

http://sharepoint/myNewSite/...

There are a lot of other pages within mySite, most of which must be redirected to the new site, but there are exceptions (e.g. user can still view the documents within the site). I thought I have to do this programmatically by somehow capturing the http request and read the url myself. Being no sharepoint guru, I had a quick google, and found that writing a web part is prehaps the best alternative for my situation.

But I'm just wondering, given my situation and needs, is writing a web part, or something programmatically, really the ideal solution? Or is there a faster and quicker way to achieve what I want using Sharepoint?

Thanks.

A: 

You can do it in three ways

  1. creating a custom HTTP Module (Good solution)
  2. Write a javascript code in your old site's master page to redirect to new page (location.href) (easy to create but navigation happens from client side)
  3. Write a webpart with a code for redirection and deploy in old site's master page (easier than point1 )
Hojo
+2  A: 

You can implement a System.Web.IHttpModule that listens to the System.Web.HttpApplication.BeginRequest event, detects whether the request url points to an old site and redirecing to the new site when necessary.

The Sharepoint part of this involves creating a Microsoft.SharePoint.Administration.SPWebConfigModification that adds the reference to your module into the web.config file of each web frontend that you have. If you implemented this as a Web Application-level feature, the code for the feature receiver activation method would look something like this:

public override void FeatureActivated(SPFeatureReceiverProperties properties)
{
    var webApplication = (SPWebApplication)properties.Feature.Parent;
    var redirectionModuleType = typeof(MyRedirectionModule);
    var modification = new SPWebConfigModification()
    {
        Name = "add[@name='MyRedirectionModule']",
        Path = "configuration/system.web/httpModules",
        Owner = "MyModule",
        Sequence = 0,
        Type = SPWebConfigModification.SPWebConfigModificationType.EnsureChildNode,
        Value = "<add name=\"MyRedirectionModule\" type=\"" + redirectionModuleType.FullName + ", " + redirectionModuleType.Assembly.FullName + "\" />"
    };
    webApplication.WebConfigModifications.Add(modification);
    webApplication.Farm.Services.GetValue<SPWebService>().ApplyWebConfigModifications();
    webApplication.Update();
}
Hirvox
A: 

Rather than modifying the Master Page you can consider automatically injecting some JavaScript logic into each page of a site collection that handles the redirect.

Have a look at our free SharePoint Infuser tool.

Muhimbi
A: 

If you are using a load balancer or a reverse proxy like ISA Server you could implement redirection rules at those levels.

Mark Mascolino
A: 

Somebody made this for you already :)

See SharePoint Smart 404 Feature. It allows you to add redirect rules to create vanity urls and handle 404s nicely.

ArjanP