create custom 404 error not found page Sharepoint online

Fekadu Deme 1 Reputation point
2021-12-05T20:48:47.563+00:00

I want to create the custom 404 error page not found page and redirect the default page not found to the custom page in SharePoint online.

Thank you!

Microsoft 365 and Office SharePoint For business Windows
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. JoyZ 18,111 Reputation points
    2021-12-06T06:05:23.387+00:00

    @Fekadu Deme ,

    Check as following to setup a Custom 404 error page for a site collection in SharePoint designer or with powershell.

    1. Create a new site page in a site collection by Site contents>Site pages>new page.
    2. Named the page like “404notfound.aspx”, customize the page with images, styles and layout you like.
    3. Open SharePoint designer 2013(you may download it from the link: Download SharePoint Designer 2013), sign in designer with your account.
    4. 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).
    5. 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:
      155183-image.png
    6. 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.



  2. Fekadu Deme 1 Reputation point
    2021-12-22T15:52:36.02+00:00

    Hello, thank you for your support. I have installed the pnp powershell and ran the following script:

    $SiteUrl="https://tenant.sharepoint.com/sites/Team1"
    $UserName="julie@tenant .onmicrosoft.com"
    $cred = Get-Credential -UserName $UserName -Message "Please enter password for $UserName"
    Connect-PnPOnline -Url $SiteUrl -Credentials $cred
    Get-PnPTenantSite -Url $SiteURL |select DenyAddAndCustomizePages
    it found that the DenyAddAndCustomizePages of site was enabled and then I ran: Set-PnPSite -Url $SiteURL -NoScriptSite $false and went through the all process. This time it was not gave me the any error, but it was not redirect to the custom page I have created. I do not really sure what is wrong. I am using my personal tenant and Pc to ran the script. Is that may be the case?

    Thank you!


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.