I have a custom 404 set up by following this:
I changed it so that the default.jsp page will now FORWARD to my DYNAMIC 404.html page. If I just allow it to stop at default.jsp, I have a 404 error code, but once it FORWARDs (not redirects), the new page that shows comes in as a 200 code.
How would I force the error code to be preserved, if forwarding the default.jsp to a content page (to keep the same dynamic content on all other pages)? I have the error code and response properly before forwarding (not redirecting), but once I get to the new page, it shows a status code of 200. Is there any way to force this? Disabling the CQ WCM Debug Filter doesn't change this for me.
Also, I turned off the WCM DEBUG filter in my author instance, which didn't make a difference - I forgot to clarify that in my post. I also ran this on a publish instance to see if I could get it working there, but I am still running into the same thing.
Can you post your code and explain what steps you took to implement this? It doesn't sound like you followed the instructions properly. If you're trying to implement a custom 404 error page, you should have a script called 404.jsp.
Justin, I followed the instructions I outlined in the link above. Once I had the 404.jsp that POINTS to the default.jsp (that the article explains to do), I modified my default.jsp to FORWARD (not redirect) to a normal content page CALLED 404. The reason I did this was to keep the dynamic links and header information coming from the main site, to the 404 page. I did this because every time I tried to do an include on the default.jsp, it would fail, thus the forward (to keep the response code) to the new page. Any ideas?
There should be no default.jsp, just a 404.jsp. I'm confused when you say "Once I had the 404.jsp that POINTS to the default.jsp". Can you explain how you did this (exact steps)?
Anyway, your content page that you forward to should have the following:
I'd recommend creating a new page component that contains this code.
When you go through the documentation on the link I sent, it specifically says:
In the repository, copy the default script(s):
So, I took the default scripts in the original location, which included BOTH 404.jsp and default.jsp. So, if you try to go through the example, you will see that I have done what is outlined, and the error page works if I just allow it to go here, but then I'm missing all of the dynamic content from my site, which is why I'm forwarding, along with doing the 'response.setStatus(404);' before forwarding. Forwarding SHOULD keep the status. Does that make more sense?
Okay, looks like default.jsp exists in CQ5.5 but not in CQ5.4. Looks like default.jsp is a generic error handler if a specific one doesn't exist.
What I think is probably going on in your case is something else is resetting the status to 200 as part of the resource resolution process for the new page. What you probably should do is set the status in the new script you are redirecting to rather than trying to do it in the 404.jsp. This makes sense anyway because what you are doing with the forward is delegating the handling of the response to some other servlet.
I don't know why I didn't think about that... I did that, and it works. So now, whenever someone goes to an error page, as long as that error page is on the 'error page template' I've created, the template will take the title of the page, and set the response status to that. So if the error page is 404.html, it will be a 404 error. PERFECT! Thanks!
Europe, Middle East and Africa