0

I am trying to redirect my users to a custom error page for 404 page not found error. I created a redirect.html and placed it in layouts/1033/ folder and executed the following script

$webapp =Get-SPWebApplication <URL>
$webapp.FileNotFoundPage = "redirect.html"
$webapp.update()

While the redirection is working good when I hit http://<webapp>/Pages/DoesntExist.aspx

But when I try some urls like

http://<webapp>/Pages/ExistingPage.dfjkdf

or

http://<webapp>/Pages/asdf/qewr

instead of redirection, the contents of redirect.html is displayed in the browser.

Below is the contents of redirect.html

<!-- _localBinding -->
<!-- _lcid="1033" _version="" -->
<html>
<head>
<meta HTTP-EQUIV="Content-Type" content="text/html; charset=utf-8" />
<meta HTTP-EQUIV="Expires" content="0" /> 
<noscript>
    <meta http-equiv="refresh" content="0; url=/_layouts/spsredirect.aspx?noscript=1" />
</noscript> 
<script language="javascript" src="/_layouts/1033/init.js"></script>
<script language="javascript" src="/_layouts/1033/core.js"></script>
<script language="javascript">                              
    var redirectURL = "/Pages/Custom404.aspx";  
    STSNavigate(redirectURL);
</script>
</head>
<body>
</body>
</html>

Is there any step I am missing?

0

Modify the redirect.html file code as below.

<!-- _localBinding -->
<!-- _lcid="1033" _version="" -->
<html>
<head>
<meta HTTP-EQUIV="Content-Type" content="text/html; charset=utf-8" />
<meta HTTP-EQUIV="Expires" content="0" /> 
<noscript>
    <meta http-equiv="refresh" content="0; url=/Pages/Custom404.aspx?noscript=1" />
</noscript> 
<script language="javascript" src="/_layouts/1033/init.js"></script>
<script language="javascript" src="/_layouts/1033/core.js"></script>
<script language="javascript">                              
    var redirectURL = "/Pages/Custom404.aspx";
    STSNavigate(redirectURL);
</script>
</head>
<body>
</body>
</html>

Or create an aspx file named as Custom404.aspx under "C:\Program Files\Common Files\microsoft shared\Web Server Extensions\14\TEMPLATE\LAYOUTS".

Replace the following line of code in redirect.html file.

var redirectURL = "/Pages/Custom404.aspx";

with

var redirectURL = "/_layouts/Custom404.aspx";

Refer to: How to create Custom 404 Error Page in SharePoint 2010

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.