KNOWLEDGE BASE
Log In    |    Knowledge Base    |    4D Home
Tech Tip: Serving a custom 404 error page
PRODUCT: 4D | VERSION: 13.0 | PLATFORM: Mac & Win
Published On: June 2, 2012

When a user of a website reqests a page that doesn't exist from a web server the response is an HTTP 404 error. From wikipedia: The 404 or Not Found error message is a HTTP standard response code indicating that the client was able to communicate with the server, but the server could not find what was requested. It is very common to send an HTML page along with this error to explain the error to the user as well as offer possible solutions.

For example see the 404 Error page from the 4d.com website. https://www.4d.com/fakepage.html

By default the 4D Web Server includes a generic 404 error page. However most websites would benifit from a custom error page that offers helpful links to the user to find their way.

If the On Web Connection method isn't being used to handle expected requests then adding the command WEB SEND FILE(error.html), where "error.html" is the name of the custom error page, will acheive this goal.

More complex webistes will be using the On Web Connection method to handle both expected and unexpected requests. Usually with a Case statement like this.

Case of
   : ($1="/Home@")
   WEB SEND FILE(home.html)
   : ($1="About@")
   About
   : ($1="/Products@)"
   ShowProducts
End case



To add the ability to serve a custom error page when an unepexted request is recieved this Case statement will be modifed to use the optional Else statement.

Case of
   : ($1="/Home@")
   WEB SEND FILE(home.html)
   : ($1="About@")
   About
   : ($1="/Products@)"
   ShowProducts
Else
   WEB SEND FILE(error.html)
End case


Again, "error.html" is the name of the custom error page.