in

SharePoint Blogs

The Best Place for SharePoint-related Blogs

The SharePoint Redemption

Saving Us from Collaboration Hell

Redirect SharePoint Site to New Location

I recently had a request to move a SharePoint subsite to a new location under a different site collection.  The site was moved over after performing the standard import/export stsadm commands.  However, the customer also wanted the old location to perform an automatic redirect for anyone still pointing to the old location.  I wanted to be able to do this without having hack up pages using designer (or other tool) or having to allow for code blocks within the default.aspx by opening my web.config up to vulnerabilities.  I found the easiest way to do this was with Javascript and a Content Editor Web Part.

  1. Add a Content Editor Web Part to the Main Page of the site.
  2. Modify the Web Part and click on Source Editor.
  3. Paste in the following code while changing the URLs to match your target.

    <HTML>
    <HEAD>
    <SCRIPT language="JavaScript">
    <!--
    function redirectsp()
      {
        top.location="
    http://sharepoint";
       }
       if (top.frames.length==0)
        {
         setTimeout('redirectsp()',0);
         }
    //-->
    </SCRIPT>
    </HEAD>
  4. <body>
    Redirecting you to the new location.  If you are not redirected, click <a href="
    http://sharepoint">HERE.</a>
    </body>
    </html>

  5. I set the redirect time to 0, but you can set it higher if you like.  1 sec = 1000, 2 sec = 2000, etc.
  6. Save the code changes.

The fun part of this solution is the fact that the code tries to load no matter what view you are in (i.e. Standard view, Edit Page, etc).  So, if you have to make changes to the code you have to let the page load but then time a press of the ESC key to keep the Javascript from loading each time.

Jeff

Published Mar 20 2008, 02:27 PM by JHolliday
Filed under: ,

Comments

 

Shandar said:

Another option for JavaScript within content editor web part would be Meta Refresh:

<meta http-equiv="refresh" content="2;url=http://MOSSURL">

The ??? Page has MOVED.

<br>

You will be automatically redirected to the new ???page.

<br>

If you are not redirected within 2 seconds, click here <a href="http://MOSSURL"> ??? Page </a>

March 20, 2008 4:07 PM
 

Links (3/20/2008) « Steve Pietrek’s SharePoint Stuff said:

Pingback from  Links (3/20/2008) &laquo; Steve Pietrek&#8217;s SharePoint Stuff

March 20, 2008 7:42 PM
 

Waldek Mastykarz said:

As these approaches are acceptable on an intranet environment, they are definitely a no-go on an Internet-facing website. First of all you shouldn't rely on the JavaScript. Second of all both redirects use the 302 redirects instead of 301. I have written more details on that subject on my blog: blog.mastykarz.nl/.../sharepoint-2007-redirect-solved-using-301-instead-of-302-redirects.

What I would do in a similar situation is to develop a Web Part which would check the state of the page and redirect the user only if checked in/published. The Web Part would of course use the 301 redirect header to fix the redirects issue on the search spiders.

March 21, 2008 1:26 PM
 

JHolliday said:

This is a great point Waldek.  I designed this strictly to work within an intranet environment.  Thank you for your feedback!

Jeff

March 21, 2008 3:06 PM

Leave a Comment

(required )  
(optional )
(required )  
Add

Need SharePoint Training? Attend a SharePoint Bootcamp!

Posts (c) their respective authors. Everything else (c) 2007 SharePoint Experts