Handling 404 errors correctly

3 posts by 2 authors in: Forums > CMS Builder
Last Post: May 15, 2013   (RSS)

By gversion - May 15, 2013

Hello,

When a listing has been deleted from my website I would like to return a 404 error with the correct HTTP Response Header.

I am aware of the following two methods but neither are doing exactly what I require:

if (!$Record) { dieWith404("Record not found!"); } // show error message if no record found

The above code seems to return the correct HTTP Response Header but I would like it to forward to users to my custom 404 error page rather than display an error message.

Therefore I have tried using the code below to redirect the user:

    if (!$Record) {     
    redirectBrowserToURL("error.html");
    exit;
} // redirect user if no record found

This code works but displays the header "HTTP/1.1 302 Moved Temporarily", which isn't correct.

Could someone please explain how I can combine the two so that I am able to forward users to my custom error page and send a 404 HTTP Repsonse Header?

Thank you,

Greg

By gversion - May 15, 2013

Hi Greg,

That's worked great, thank you very much.

Regards,

Greg