What function to I use to redirect to the default 404 error page? Sample code appreciated. Thank you!
+1
A:
abort(404)
as mentioned in the quickwiki tutorial. See the docs for abort.
Heikki Toivonen
2010-04-02 06:56:00
A:
404 isn't something you redirect to; there's no distinct "404 page" with its own distinct URL. It's a status code that you send back in the HTTP response, instead of 200 (the code for a normal successful response).
Actual redirects are also status codes, such as 301 or 307, that can be used instead of 200 or 404.
Read about the status line in an HTTP response for more info.
Wyzard
2010-04-02 07:11:19
This is not true. The server sends back a special 404 error page that developers can customize to their needs. Try entering a non-existing URL at stackoverflow.com, for example.
Heikki Toivonen
2010-04-14 16:11:44
@Heikki Toivonen: A 404 response can contain a body with HTML (or anything else) in it, but there's no redirect involved. A redirect means you ask for one URL, and the server responds with another URL that your browser should load instead. If you enter a nonexistent URL at stackoverflow.com, and then look in your address bar, you'll find that it hasn't changed. The server didn't redirect you to the URL of a "page-not-found error message page", it just sent you the "page not found" message in response to the URL you requested.
Wyzard
2010-04-15 00:00:43
@Wyzard: Fair enough.
Heikki Toivonen
2010-04-15 16:20:43