1,804 articles and 14,421 comments as of Sunday, January 2nd, 2011

EndUserSharePoint has combined resources with NothingButSharePoint.com. You can now find End User (Mark Miller), Developer (Jeremy Thake) and IT Pro SharePoint (Joel Oleson) content all in one place!

This site is a historical archive and is no longer being updated. Please update your favorites, bookmarks and RSS feeds.

NothingButSharePoint.com
Wednesday, January 20, 2010

Redirect a SharePoint site by using the Content Editor Web Part

Author: Devin Walker
DLOCC, Inc.

This blog demonstrates a useful way to use the Content Editor Web Part to redirect users of a particular site. The script prompts a site’s end users they will be redirected and then redirects them after a certain period of time.


At some point in time you might want to point users to another location from a specific page and prompt them before doing so. I will show you how to do this using the Content Editor Web Part. It is rather easy. First, you must have proper permissions on the page or site that you are trying to redirect users. Second, be advised that this may not be best practice to use the CEWP. For my situation, I needed a way to direct users from a page without actually moving or deleting the page. This worked great for my needs, yours may be different. Anyways here we go:

  1. First click Site Actions > Edit Page in the top right section of your browser window. Now MOSS will effectively checkout the page in your account name.

  2. Next we are going to add the Content Editor Web Part to a zone of your choice; it doesn’t really matter since users won’t be using the page. This is done several ways, let’s just click on the Add a Web Part button ontop of the zone you chose.

  3. This will bring up the Add a Web Part window. Scroll down to the Content Editor Web Part.

  4. This will place the CEWP into the Top Zone or whichever zone you added it to. Let’s modify the web part. This is done by clicking Edit > Modify Shared Web Part.

  5. Once we have clicked the modify button a window opens on the right hand side of the browser with various options for the web part. We want to add our code the webpart so we will click the Source Editor… button.

  6. Good, almost done… we just need to copy and paste the following code:
<SCRIPT type='"text/javascript"'>// <![CDATA[
alert("This site has been moved to another location, please update all existing bookmarks.  You will be redirected momentarily.");
// ]]></SCRIPT>

Into the Source Editor Windows that pops up when we clicked the Source Editor… button.


Great! Now all you have to do is click the Save button, publish the page and your done. Users who navigate to this page will be greeted with a popup and redirected in 10 seconds (the default time). Please note: If you want to change the amount of time before the redirect simply change the number of seconds by editing the following number representing the time lapse:

<meta http-equiv="refresh" content="10;url=http://MYSERVERNAME.com/Pages/default.aspx">

If you want a webpart with some more functionality then check out the SharePoint Redirect Webpart

Author: Devin Walker
DLOCC, Inc.

About: Devin Walker is a professional web designer, SharePoint enthusiast and founder of the consulting company DLOCC, Inc.. Devin has years of experience working with companies of all sizes to successfully implement, test and launch SharePoint enterprise content management systems. He writes about his experiences on his blog: DLOCC | Articles and Tutorials 

 

Please Join the Discussion

20 Responses to “Redirect a SharePoint site by using the Content Editor Web Part”
  1. So easy even I can do it!! Thanks Devin, more of this cool easy stuff in CEWP’s please.

  2. Devin Walker says:

    You’re welcome : ]

  3. Christophe says:

    Kevin, I am surprised that as a professional Web designer you suggest to put a meta tag inside the body of a Web page, which AFAIK is against Web standards. Please correct me if I’m wrong.

    There are other ways to do redirects. You can use the window.location.href property for that.

  4. Christophe says:

    [sorry for the typo in your name btw]

  5. Devin Walker says:

    Christophe,

    I am well aware of this an mention that when using this method to “be advised that this may not be best practice” and I fail to see how using it for this purpose would cause any harm. You do bring up a valid point that there are a lot of other ways to do redirects. This is just the method I chose when writing this article.

  6. Jorgen B says:

    @Christophe
    Con you describe the approach using the window.location.href property for the End User (i.e. me…)

    J

  7. Christophe says:

    Off the top of my head: instead of using the meta tag, change the script to this:
    alert(”This site has been moved to another location, please update all existing bookmarks. You will be redirected momentarily.”);
    window.location.href = “http://MYSERVERNAME.com/Pages/default.aspx”;

    It’ll be a little more complicated if you need a countdown.

    Also, a side note: keep in mind the ?contents=1 trick, as after you include a redirect it will become difficult to edit the page.

  8. Neil Radulski says:

    I get the redirect but I don’t get the pop up. I’ve done the idiot checks on my MOSS 2007 publishing site and still can’t figure out why no pop up.

  9. Mike says:

    A related question…I think.

    We have a Sharepoint site (WSS 3.0), where the user created a redirect on the default.aspx (i’m not sure exactly how they did it, so it may not be the same method you described). Our problem is that we want to stop the redirect. However, we can’t get in to edit the web parts … it keeps redirecting us on the “edit this page” screen. We tried to use the “reset site definition” on that page, but it doesn’t seem to do anything…Any ideas? Thanks.

  10. Christophe says:

    Mike, that’s exactly the issue I mentioned in my earlier comment.

    If the redirect has been added through a Web Part, append ?contents=1 to the URL and this will send you to the maintenance page.
    If not, you’ll need to look at the source code (for example using SharePoint Designer).

  11. Shafi says:

    Hi i have redirected my sharepoint home page by using source editor and adding the script you mentioned. I have included contents=1, so it redirects in 1 second to a different page. I want it to change back to 10. By the time I click on edit page it redirects. How can I change the time in the script now. Thanks for your help.

  12. Chris says:

    I get the redirect but, not the pop up alert…using WSS 3.0…help.

  13. Shafi says:

    Hi i have redirected my sharepoint home page by using source editor and adding the script you mentioned. I have included contents=1, so it redirects in 1 second to a different page. I want it to change back to 10. By the time I click on edit page it redirects. How can I change the time in the script now. Thanks for your help.

    _______________________________________________________________________________
    1 second was enough for closing the webpart, you ve to be very quick. So, I closed the webpart and created a new one with time to redirect in 4 seconds. Don`t make the time to be zero, otherwise you cannot get to the page and edit it.

  14. Bill Garvey says:

    Can you just disable Java in your browser (method varies from browser to browser). Then the redirect can’t fire, and you can edit at will.

    Do a quick google search on “disable javascript IE 6″ or whatever browser and version you have.

  15. Elbio says:

    Hey thanks for posting this. I needed it quick and functional and this is it! I sincerely appreciate it.

  16. Subrato says:

    Devin, how would I redirect to a specific site based on the user role? Say the user is supposed to go to their MySite under their login, is there any easy way to accomplish this ?

  17. Greg says:

    Thanks! Worked very well in an environment where other options were not available. :-)

  18. Maia says:

    I’ve done this and my site is redirecting. However, it’s not going to a different page (yes, I included a URL that was not the same as the page I set this up on). Is this a script error? Or … Is it because i have editing permissions — guessing not or you would have mentioned …. but i just ask cause I’m hoping it will work for my visitors. Anyway, all I can see right now is the same page resetting itself every 10 seconds. Suggestions appreciated!

Trackbacks

Check out what others are saying about this post...
  1. [...] Redirect a SharePoint site by using the Content Editor Web Part [...]




Notify me of comments to this article:


Speak and you will be heard.

We check comments hourly.
If you want a pic to show with your comment, go get a gravatar!