I'm trying to support a CQ5 (5.5) installation developed by an outside firm for my company.
It appears that my company wanted a pretty 404 page that looked like the rest of the site, and using the custom Sling 404.jsp error handler to redirect to a regular page that merely says "Page Not Found" was the easiest way to do it. The problem is that the 404 page actually returns a 200 status code since it really is just a regular content page that bears a "Not Found" message on it.
This is causing us problems with Google and the GoogleBot, since Google believes all the old search links to now non-existent pages are still valid (200 status code).
Is there any way to configure CQ to return the appropriate 404 status code for the "not found" HTML page that we display? When I am in the CQ Author mode editing the page, I find nothing in page properties or in components that could be added to the page.
Any help would be appreciated, as CQ is not exactly my area of expertise.
You'll have to overlay /libs/sling/servlet/errorhandler/404.jsp
file in order to do so - copy it to /apps/sling/servlet/errorhandler/404.jsp
and change according to your specification.
And if you are looking specifically into setting appropriate response status code - you can do it by setting respective response
property:
response.setStatus(404);
UPDATE: instead of redirecting to the page_not_found.html
you might want to include it to the 404.jsp after setting response status:
<sling:include path="path/page_not_found.html" />