Microsoft Knowledge Base Email Alertz

How to point to a custom 404 error Web page in Windows SharePoint Services 3.0 or in Microsoft Office SharePoint Server 2007

Search KbAlertz

Advanced Search

Receive Microsoft Knowledge Base articles by E-Mail?

Every night we scan the Microsoft Knowledge Base. If technologies you're interested in are updated, we'll send you an e-mail. You only get one e-mail a day, and only when new articles are added.

Click here to create a
FREE account
Already have an account?
[Click here to Login]











Microsoft Knowledge Base Article

This article contents is Microsoft Copyrighted material.
©2005-©2007 Microsoft Corporation. All rights reserved. Terms of Use | Trademarks

Article ID: 941329 - Last Review: September 22, 2011 - Revision: 8.0

How to point to a custom 404 error Web page in SharePoint

INTRODUCTION

This article describes how to point to a custom 404 error Web page in Windows SharePoint Services 3.0, in Microsoft Office SharePoint Server 2007, or in Microsoft SharePoint Server 2010.

MORE INFORMATION

Windows SharePoint Services 3.0 or SharePoint Server 2007

To configure Windows SharePoint Services 3.0 or SharePoint Server 2007 to point to a custom 404 error Web page, follow these steps.

Note Because of a design limitation, the custom 404 error Web page does not work when you access invalid site collections.
  1. Log on to the computer that is running SharePoint Server 2007 by using an account that has administrative permissions.
  2. In Windows Explorer, locate the following folder:
    %systemdrive%\Program Files\Common Files\Microsoft Shared\Web Server Extensions\12\TEMPLATE\LAYOUTS\LangID
    Notes
    • In this path, %systemdrive% represents the actual drive name of the drive on which the operating system is installed.
    • In this path, LangID represents the actual language ID of the language that you use. For example, 1033 is the language ID for U.S. English.
  3. Create the custom HTML file. To do this, use the appropriate method.

    Microsoft Office SharePoint Server 2007

    1. On the computer that is running SharePoint Server 2007, copy the Sps404.html file to a temporary folder.
    2. Rename the Sps404.html file. For example, give the file the following name:
      Custom404.html
    3. Add the custom content to the Custom404.html file.
    4. Copy the Custom404.html file to the %systemdrive%\Program Files\Common Files\Microsoft Shared\Web Server Extensions\12\TEMPLATE\LAYOUTS\LangID folder.

    Windows SharePoint Services 3.0

    1. On the computer that is running Windows SharePoint Services 3.0, locate the existing Error.htm file in the following folder:
      %systemdrive%\Program Files\Common Files\Microsoft Shared\Web Server Extensions\12\TEMPLATE\LAYOUTS\LangID
      Notes
      • In this path, %systemdrive% represents the actual drive name of the drive on which the operating system is installed.
      • In this path, LangID represents the actual language ID of the language that you use. For example, 1033 is the language ID for U.S. English.
    2. Copy the Error.htm file to a temporary folder.
    3. Rename the Error.htm file. For example, give the file the following name:
      Custom404.htm
    4. Modify the Custom404.htm file as required.
    5. Copy the Custom404.htm file to the %systemdrive%\Program Files\Common Files\Microsoft Shared\Web Server Extensions\12\TEMPLATE\LAYOUTS\LangID folder.
  4. Create a custom console application by using Microsoft Visual Studio 2005 Professional Edition or Microsoft Visual Studio 2005 Standard Edition. Then, add the following code to the custom console application.
    // The following code assumes that a reference is made to Microsoft.SharePoint.
    
    Microsoft.SharePoint.Administration.SPWebApplication webapp = 
    Microsoft.SharePoint.Administration.SPWebApplication.Lookup(new Uri("http://<serverurl>"));
                webapp.FileNotFoundPage = "<Custom404.htm>";
                webapp.Update();
    
    Notes
    • In this code, <serverurl> represents the actual URL of the computer that is running SharePoint Server 2007.
    • In this code, <Custom404.htm> represents the actual name that you created for the custom HTML file.
    For more information about how to create a custom console application by using Visual Studio 2005, visit the following Microsoft Web site:
    http://msdn2.microsoft.com/en-us/library/ms438026.aspx (http://msdn2.microsoft.com/en-us/library/ms438026.aspx)
    Note By default in Windows SharePoint Services 3.0 and in SharePoint Server 2007, the FileNotFoundPage property is set to the "null" setting.
  5. Run the custom console application on the computer that is running SharePoint Server 2007.
Note By default in Windows Internet Explorer, the Show friendly HTTP error messages setting is turned on. In this case, the custom error page may not appear. For more information about this setting, click the following article number to view the article in the Microsoft Knowledge Base:
218155  (http://kbalertz.com/Feedback.aspx?kbNumber=218155/ ) Description of Hypertext Transport Protocol Error Messages

SharePoint Server 2010

To configure SharePoint Foundation server or SharePoint Server 2010 to point to a custom 404 error Web page, follow these steps.   
  1. Log on to the computer that is running SharePoint Server 2010 by using an account that has administrative permissions. 
  2. In Windows Explorer, locate the following folder: 

    %systemdrive% \Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\TEMPLATE\LAYOUTS\LangID 

    Notes

    • In this path, %systemdrive% represents the actual drive name of the drive on which the operating system is installed.  

    • In this path, LangID represents the actual language ID of the language that you use. For example, 1033 is the language ID for U.S. English. 
  3. Create the custom HTML file:
    1. On the computer that is running SharePoint Server 2010, copy the Sps404.html file to a temporary folder. 
    2. Rename the Sps404.html file. For example, give the file the following name: 

      Custom404.html
    3. Add the custom content to the Custom404.html file by using an HTML editor. 
     
  4. Copy the Custom404.html file to the %systemdrive% \Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\TEMPLATE\LAYOUTS\LangID folder.
  5. Run the following PowerShell commands from the SharePoint 2010 Management Shell:
    $webapp =Get-SPWebApplication http://<serverUrl>:<port>
    $webapp.FileNotFoundPage = "Custom404.html"
    $webapp.update()


    Verify that the property is set by running the following command:

    (Get-SPWebApplication http://<serverUrl>:<port>).FileNotFoundPage



    Notes

    • In this code, <serverUrl> represents the actual URL of the Web application where you are setting the custom 404 error page. 

    • In this code, <port> represents the nonstandard port number, if any, that is assigned to the Web application. 

    • In this code, Custom404.html represents the actual name that you created for the custom HTML file.  

    For more information about how to use PowerShell scripts against SharePoint 2010, visit the following Microsoft Web site: 

    Windows PowerShell for SharePoint Foundation 2010 (http://msdn.microsoft.com/en-us/library/ee536539(office.14).aspx)

    Note By default in SharePoint Server 2010, the FileNotFoundPage property is set to the "null" setting.
 

APPLIES TO
  • Microsoft Office SharePoint Server 2007
  • Microsoft Windows SharePoint Services 3.0
  • Microsoft SharePoint Foundation 2010
  • Microsoft SharePoint Server 2010
Keywords: 
kbexpertiseinter kbhowto KB941329
       

Community Feedback System

Very often, it takes hours to solve a problem. Very often, you've looked high and low, and have tried a lot of solutions. When you finally found it, chances are, it was because someone else helped you. Here's your chance to give back. Use our community feedback tool to let others know what worked for you and what didn't.

Please also understand that the community feedback system is not warranted to be correct, it's simply a system that we've built to let people try and help each other. If something in a feedback response doesn't make sense to you, or you're not comfortable making changes that the feedback talks about (like registry edits), please consult a professional.

Thank you for using kbAlertz.com Feedback System.

-- Scott Cate

Pratap Raju Report As Irrelevant  
Written: 6/12/2008 3:34 PM
This seems to be working within a site collection context only, i.e. http://server/sites/mysite if mysite doesn't exist in MOSS then this URL will NOT trigger the error page set to SPWebApplication.FileNotFoundPage property(custom404.html). SPUtilityInternal Send404 will return a string "404 FILE NOT FOUND".

KodeKreachor Report As Irrelevant  
Written: 9/26/2008 12:11 PM
Unfortunately this solution will not do any good if the client has the 'Show friendly HTTP error messages' option enabled in IE. Can anyone prove this statement wrong?

Adam - www.roderickcg.com Report As Irrelevant  
Written: 1/20/2009 10:32 AM
The custom error pages must be over 512 bytes in size. http://support.microsoft.com/kb/218155

Heiko Report As Irrelevant  
Written: 2/7/2009 1:38 PM
why not in web.config with own error site links ? <customErrors defaultRedirect="ErrorPage.aspx" mode="On"> <error statusCode="404" redirect="http://litwaredemo/sites/error404/default.aspx" /> Regards