SharePoint Online: How to Implement Custom 404 Page Not Found Error Page?
Requirement: Implement a custom page not found error page in SharePoint Online.
SharePoint Online: How to Add custom 404 page not found error page
SharePoint Online comes with a default "Page not found" error page in "Pages" library in publishing Sites (http://crescent.sharepoint.com/Pages/PageNotFoundError.aspx) which works automatically when a user hits a non-existent URL. This error page works for the entire site collection.
You can further customize this page, located at "/Pages/PageNotFoundError.aspx" to add some descriptive text, images and branding. In some cases, You may need to create your own 404 page and here are the steps:
Step 1: Add New Page Not Found Error Page in SharePoint Online:
We can create our own page and set as a page not found error page for any SharePoint Online site collection. Here are the steps to create a custom 404 page not found error page:
Step 2: Set Default 404 Page Not Found Error page:
Once the custom error page is ready, the next step is to configure the page as a default 404 page not found error page. This can be done either through PowerShell or using SharePoint Designer.
Option 1: PowerShell to Set Custom Error page in SharePoint Online:
To set a custom page not found error page, we need to update the "vti_filenotfoundpage" key in the property bag of the root site object. Here is the PowerShell script to set custom error page for a site collection.
Option 2: Using SharePoint Designer to set Custom Page not found error page:
You can also use SharePoint designer to set the custom page not found error page: Here is how:
Can I implement custom page not found error page without activating Publishing Feature?
How about non-publishing sites? How to add custom 404 error pages in Team sites? Here is how:
SharePoint Online: How to Add custom 404 page not found error page
SharePoint Online comes with a default "Page not found" error page in "Pages" library in publishing Sites (http://crescent.sharepoint.com/Pages/PageNotFoundError.aspx) which works automatically when a user hits a non-existent URL. This error page works for the entire site collection.
You can further customize this page, located at "/Pages/PageNotFoundError.aspx" to add some descriptive text, images and branding. In some cases, You may need to create your own 404 page and here are the steps:
Step 1: Add New Page Not Found Error Page in SharePoint Online:
We can create our own page and set as a page not found error page for any SharePoint Online site collection. Here are the steps to create a custom 404 page not found error page:
- Go to Site Contents >> Pick Pages Library and Create New >> Error Page
- Customize the error page with your own styles, images and save.
Step 2: Set Default 404 Page Not Found Error page:
Once the custom error page is ready, the next step is to configure the page as a default 404 page not found error page. This can be done either through PowerShell or using SharePoint Designer.
Option 1: PowerShell to Set Custom Error page in SharePoint Online:
To set a custom page not found error page, we need to update the "vti_filenotfoundpage" key in the property bag of the root site object. Here is the PowerShell script to set custom error page for a site collection.
#Load SharePoint CSOM Assemblies Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.dll" Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.Runtime.dll" #Set Variables $SiteURL = "https://crescent.sharepoint.com/sites/marketing" $CustomPageNotFoundURL = "/sites/marketing/Pages/404.aspx" #Get Credentials to connect $Cred = Get-Credential Try { #Setup the context $Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL) $Ctx.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Cred.UserName,$Cred.Password) #Get the Root Web and its Property Bag $Web = $Ctx.Web $Ctx.Load($Web) $Ctx.Load($Web.AllProperties) $Ctx.ExecuteQuery() #Update the Key value in Property bag $Web.AllProperties["vti_filenotfoundpage"] = $CustomPageNotFoundURL $Web.Update() $Ctx.ExecuteQuery() Write-Host -f Green "Custom 404 Page Not Found Error page has been Set!" } Catch { write-host "Error: $($_.Exception.Message)" -foregroundcolor Red }
Option 2: Using SharePoint Designer to set Custom Page not found error page:
You can also use SharePoint designer to set the custom page not found error page: Here is how:
- Open your SharePoint Online site collection in SharePoint Designer 2013
- Select the Site object on the left side navigation, Click on Site Options button in the ribbon
- Assign the "vti_filenotfoundpage" property of the site to a Custom Error Page URL that you created. (Add a new entry, if it doesn't exist)
- Click on "OK" button to commit your changes.
Can I implement custom page not found error page without activating Publishing Feature?
How about non-publishing sites? How to add custom 404 error pages in Team sites? Here is how:
- Navigate to your SharePoint Online site collection, Pick any document library (E.g. "Site Assets")
- Enable Content type by: Click on Settings >> Library Settings >> Advanced Settings >> Set "Yes" for "Allow management of content types" option and click on "OK" in the bottom of the page
- Now, in Library Settings page, under "Content Types", Click on "Add from existing site content types" link
- Add "Basic Page" content type to the Library. Now, Go back to the library >> Click on "New" >> Basic Page >> Give a name to your error page (E.g. 404) and click on "Create"
- Add some descriptive text and image to the page and save!
Nice article, saved me a lot of time :-)
ReplyDelete