Check as following to setup a Custom 404 error page for a site collection in SharePoint designer or with powershell.
- Create a new site page in a site collection by Site contents>Site pages>new page.
- Named the page like “404notfound.aspx”, customize the page with images, styles and layout you like.
- Open SharePoint designer 2013(you may download it from the link: Download SharePoint Designer 2013), sign in designer with your account.
- Open site in designer, if you have admin right but got 403 forbidden error, make sure the site is enable custom script.(For more info: Allow or prevent custom script).
- Select Site Options at top ribbons, find parameters named vti_filenotfoundpage, if you don’t have it, please create a new one. In Value filed, type the path of the custom 404 error page you created, such as screenshot below:
- Click OK and Apply, now if User type wrong link under the site, he will be redirect to the customized page.
You can also use Powershell to change the vti_filenotfoundpage property of specific 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/SitePages/404notfound.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
}
If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.