Collaborate, Innovate, Automate

Set 404 Error Page

This PnP PowerShell script configures a custom 404 error page for SharePoint Online sites. A custom 404 error page provides a better user experience when users navigate to non-existent pages or broken links within your SharePoint site.

Purpose

Setting up a custom 404 error page helps improve user experience by:

Prerequisites

Setup Instructions

  1. Create your 404 page in the Site Pages library - Design and publish a custom page that will serve as your error page
  2. Turn on custom scripting for the site - This is required to modify the property bag values
  3. Update the script with your tenant, site and page details and run it!

PowerShell Script


# Set your Client ID (optional - leave empty for interactive authentication)
$ClientId = ""

# Connect to your SharePoint Online site
Connect-PnPOnline -Url "https://tenantName.sharepoint.com/sites/siteName" -Interactive -ClientId $ClientId

# Set the property bag value to configure the custom 404 error page
Set-PnPPropertyBagValue -Key "vti_filenotfoundpage" -Value "/sites/siteName/SitePages/pageName.aspx"
          

Usage Notes

Best Practices

Example Values