Get Custom Not Found Page to Return 404 Status Code?
Is it possible to get Umbraco to return a "proper" 404 status code instead of 200 OK for the custom page not found page? I know the standard .Net error handling does the same thing, but I can get round that by adding:
Response.StatusCode=404;
to the page. If I try and do the same in Umbraco, it just fires off the 404 handler again, effectively resulting in an infinite loop as the custom 404 page throws a 404 status, and then gets redirected back to itself and so on.
I've not really found much on this from looking so far, I'm sure someone must have found a way round this! Any help or pointers greatly appreciated.
Sorted, I needed to tell it to ignore IIS errors as well. Adding the following code to the template for the 404 page sorts it (you could add similar code in an XSLT extension I guess too):
This is the important bit: Response.TrySkipIisCustomErrors = true; if you don't have that line in and you're running IIS7 or above, you'll run into the infinite looping that I described earlier! Hope that helps anyone else who has this problem!
Umbraco 4.11.8 should return actual 404 statuses for not found content (this was a bug on much older versions of Umbraco). How have you wired in the 404 page? Are you using the customerrors section in the web.config file, or the Umbraco 404 page configuration in umbracoSettings.config?
I'm also using the Umbraco package URL Tracker v2.2.3 by Stefan Kip. This and Google Webmaster Tools confirm that there are hundreds of dead links from our previous site still considered to be "OK" and therefore working in the live site.
The built in IIS error handlers using the CustomErrors section in web.config all return 200 statuses, something I REALLY wish Microsoft would fix, as its wrong.
I'm wondering if the IIS error setting is overriding the Umbraco one. In your umbracoSettings.config file, there should be a setting called "trySkipIisCustomErrors" near the bottom somewhere. Try setting that to true and see if it solves the 404 returning the wrong status!
My guess would be that the first and last are being handled by Umbraco, but the other two are being handled by the IIS handler (as they're not file types that are usually handled by the ASP.Net pipeline).
Try setting a different URL for the IIS 404 to see if that's the case. If it is, you may need to map the .asp/.html extensions to the aspnet ISAPI filter. Does your site make use of asp/vbscript or plain html files?
Tim, any chance you could explain the mapping in more detail please? I followed the steps here and am seeing exactly the same as John. although my pages which are coming back as 200 are using the custom 404 page, while the ones returning actual 404 codes are using the 'this page intentionally left ugly' page.
Tim, there are no asp/vbscript or plain html being used. And RE: "...different URL for the IIS 404..." - and - ".. map the .asp/.html extensions..." these are beyond my reach.
I installed it on my local build and I could right click my home node in the content menu, and by selecting the 404 page I could set it.
However, when I installed it on my development server the following happens.
I right click the home node in the content menu, select 404, and instead of showing me the content picker it loads the 404 page itself into the window!
I am using Umbraco version 7.3.1 assembly: 1.0.5780.28249
yes, its the same on my local and development build
I've tried removing the error settings in umbracosettings.config and on IIS and now the window is blank, looks like there's something missing from the package install on the development build but I can't see what.
I have just tried your method using theskipTisCustomErrors on a 7.2.1 build Yogesh, but sadly I get config errors. It doesn't recognise disableAlternativeTemplates or disableFindContentByIdPath
I persevered with the package and found that locally I had files in App_Plugins/PageNotFoundManager, whereas on the server that file did not exist.
I checked the permissions settings for V7 and it doesn't mention the App+Plugins folder, but I added permissions to that anyway and uninstalled/reinstalled the package
after installing the page displayed a file not found message and the site went down due to an error in the web.config.
I tweaked it to read
Running 7.5.8 here. The above solution did not provide the 404 status code for me. What worked is setting httpErrors response to "PassThrough" and in UmbracoSettings.config, specifying the 404's page id in a <error404> tag. It's described here: http://letswritecode.net/articles/how-to-setup-custom-error-pages-in-umbraco/ I think setting the response to PassThrough means I will also need to configure the 404 error page in IIS.
Get Custom Not Found Page to Return 404 Status Code?
Is it possible to get Umbraco to return a "proper" 404 status code instead of 200 OK for the custom page not found page? I know the standard .Net error handling does the same thing, but I can get round that by adding:
Response.StatusCode = 404;
to the page. If I try and do the same in Umbraco, it just fires off the 404 handler again, effectively resulting in an infinite loop as the custom 404 page throws a 404 status, and then gets redirected back to itself and so on.
I've not really found much on this from looking so far, I'm sure someone must have found a way round this! Any help or pointers greatly appreciated.
:)
Sorted, I needed to tell it to ignore IIS errors as well. Adding the following code to the template for the 404 page sorts it (you could add similar code in an XSLT extension I guess too):
protected override void Render(HtmlTextWriter writer)
{
base.Render(writer);
Response.TrySkipIisCustomErrors = true;
Response.StatusCode = 404;
Response.StatusDescription = "404 Page Not Found";
}
This is the important bit: Response.TrySkipIisCustomErrors = true; if you don't have that line in and you're running IIS7 or above, you'll run into the infinite looping that I described earlier! Hope that helps anyone else who has this problem!
Excellent Tim - thanks!
Hi Tim
I'm having exactly this problem - all url errors are routed to my 404 page which works OK but the page returns "200 OK" to the caller.
I do not understand how to "add the code to the 404 template".
I'm running umbraco v 4.11.8
Regards
John Perryn
Hi John,
Umbraco 4.11.8 should return actual 404 statuses for not found content (this was a bug on much older versions of Umbraco). How have you wired in the 404 page? Are you using the customerrors section in the web.config file, or the Umbraco 404 page configuration in umbracoSettings.config?
Hi Tim, and thanks.
You can see my error 404 page here http://www.qfhs.org.au/zzzz
I'm using the Chrome extension "Postman" to view headers etc. This clearly shows 200 OK for the above link
web.config has only [customErrors mode="RemoteOnly" defaultRedirect="runtime_error/" /]
The runtime_error page appears correctly in stead of YSOD. eg http://www.qfhs.org.au/xxx/%20 however this page also returns status 200 OK to the user.
umbracoSettings.config has: [error404] 1075 [/error404]
IIS server custom error handler for 404 redirects to http://www.qfhs.org.au/error-page/ which has nodeId = 1075 of course.
I'm also using the Umbraco package URL Tracker v2.2.3 by Stefan Kip. This and Google Webmaster Tools confirm that there are hundreds of dead links from our previous site still considered to be "OK" and therefore working in the live site.
Regards and thanks again
John Perryn
The built in IIS error handlers using the CustomErrors section in web.config all return 200 statuses, something I REALLY wish Microsoft would fix, as its wrong.
I'm wondering if the IIS error setting is overriding the Umbraco one. In your umbracoSettings.config file, there should be a setting called "trySkipIisCustomErrors" near the bottom somewhere. Try setting that to true and see if it solves the 404 returning the wrong status!
Hi Tim
Yes, excellent. That appears to have worked. A simple test is showing 404 again. I'll do more testing but happy to mark that as a soved problem.
Merry Christmas from Australia.
John Perryn
Strange results now.
http://www.qfhs.org.au/xxx -> 404
http://www.qfhs.org.au/xxx.html -> 200
http://www.qfhs.org.au/xxx.asp -> 200
http://www.qfhs.org.au/xxx.aspx -> 404
Hi John,
My guess would be that the first and last are being handled by Umbraco, but the other two are being handled by the IIS handler (as they're not file types that are usually handled by the ASP.Net pipeline).
Try setting a different URL for the IIS 404 to see if that's the case. If it is, you may need to map the .asp/.html extensions to the aspnet ISAPI filter. Does your site make use of asp/vbscript or plain html files?
Tim, any chance you could explain the mapping in more detail please? I followed the steps here and am seeing exactly the same as John. although my pages which are coming back as 200 are using the custom 404 page, while the ones returning actual 404 codes are using the 'this page intentionally left ugly' page.
Thanks Aaron.
Tim, there are no asp/vbscript or plain html being used. And RE: "...different URL for the IIS 404..." - and - ".. map the .asp/.html extensions..." these are beyond my reach.
Rgds
John P
Hi All, I am having the same issue , custom 404 returning status code 200 Ok , how to fix this in umbraco 7.2 any help?
Yogesh
Did you ever work out a solution for this yogesh? I'm having the same issue.
Comment author was deleted
You can also just use this package https://our.umbraco.org/projects/backoffice-extensions/umbraco-page-not-found-manager/ , should return the correct code
Hi Tim
Thanks for that.
I installed it on my local build and I could right click my home node in the content menu, and by selecting the 404 page I could set it.
However, when I installed it on my development server the following happens.
I right click the home node in the content menu, select 404, and instead of showing me the content picker it loads the 404 page itself into the window!
I am using Umbraco version 7.3.1 assembly: 1.0.5780.28249
Any hints or tips?
Comment author was deleted
Same Umbraco version?
yes, its the same on my local and development build
I've tried removing the error settings in umbracosettings.config and on IIS and now the window is blank, looks like there's something missing from the package install on the development build but I can't see what.
Hey Shaun, try setting up trySkipIisCustomErrors=false in your UmbracoSettings.config
see the screenshot
Yogesh
I have just tried your method using theskipTisCustomErrors on a 7.2.1 build Yogesh, but sadly I get config errors. It doesn't recognise disableAlternativeTemplates or disableFindContentByIdPath
Thanks Yogesh. Did you use this in addition to the page not found package that Tim has suggested, or as an alternative?
no i am not using any package, just the 404 page id setting and this one
Thanks Yogesh
I persevered with the package and found that locally I had files in App_Plugins/PageNotFoundManager, whereas on the server that file did not exist.
I checked the permissions settings for V7 and it doesn't mention the App+Plugins folder, but I added permissions to that anyway and uninstalled/reinstalled the package
after installing the page displayed a file not found message and the site went down due to an error in the web.config. I tweaked it to read
I was then able to set the 404 page in the content tree. and the package worked perfectly!
My 404 custom page now returns 404 status!
great, cheers :)
Yogesh
Running 7.5.8 here. The above solution did not provide the 404 status code for me. What worked is setting httpErrors response to "PassThrough" and in UmbracoSettings.config, specifying the 404's page id in a <error404> tag. It's described here: http://letswritecode.net/articles/how-to-setup-custom-error-pages-in-umbraco/ I think setting the response to PassThrough means I will also need to configure the 404 error page in IIS.
is working on a reply...