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 ( which works automatically when a user hits a non-existent URL. This error page works for the entire site collection.

sharepoint online custom page not found

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 it 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.

Make sure you have enabled the custom script prior to setting Property bag values!

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 = ""
$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
    #Update the Key value in Property bag
    $Web.AllProperties["vti_filenotfoundpage"] = $CustomPageNotFoundURL
    Write-Host -f Green "Custom 404 Page Not Found Error page has been Set!"
Catch {
    write-host "Error: $($_.Exception.Message)" -foregroundcolor Red

You can also set 404 Error page using PnP PowerShell as:

Set-PnPPropertyBagValue -Key "vti_filenotfoundpage" -Value "/sites/Your-site-url/SitePages/Page-not-found.aspx"

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)
    sharepoint online custom 404 page
  • Click on “OK” button to commit your changes.

Can I implement a 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!

Now, You have your custom error page ready. You can use either PowerShell or SharePoint Designer methods described above to set the custom page not found error page for SharePoint Online!

Salaudeen Rajack

Salaudeen Rajack is a SharePoint Architect with Two decades of SharePoint Experience. He loves sharing his knowledge and experiences with the SharePoint community, through his real-world articles!

One thought on “SharePoint Online: How to Implement Custom 404 Page Not Found Error Page?

  • September 6, 2019 at 3:58 PM

    Nice article, saved me a lot of time 🙂


Leave a Reply