KNOWLEDGE BASE
Log In    |    Knowledge Base    |    4D Home
Tech Tip: How to return a custom 404 page
PRODUCT: 4D | VERSION: 11 | PLATFORM: Mac & Win
Published On: February 26, 2009

In 4D v11 SQL, a custom 404 page can easily be accomplished by modifying the "On Web Connection" database method to include the following code:

WebFolder:=Get 4D folder(HTML Root Folder )

requestedFile:=WebFolder+(Replace string($1;"/";"\\"))

If ((Test path name(requestedFile)<0))
     ` Handle the 404 error
    SEND HTML TEXT("404")
End if


Note: The above code was written for Windows and replaces the forward slashes ("/") with the Windows path delimiter which is a back slash ("\\"). On a Macintosh computer the forward slashes ("/") will need to be replaced with the Mac path delimiter which is a colon (":")

The above sample code simply returns the text "404" to the browser in the case of an invalid request. You could of course handle this error however you see fit; some of the more frequently used commands may include:

SEND HTML FILE: http://www.4d.com/docs/CMU/CMU00619.HTM
SEND HTML BLOB: http://www.4d.com/docs/CMU/CMU00654.HTM
SEND HTTP REDIRECT: http://www.4d.com/docs/CMU/CMU00659.HTM
SEND HTML RAW DATA: http://www.4d.com/docs/CMU/CMU00815.HTM

For more information about the "On Web Connection" database method please see: http://www.4d.com/docs/CMU/CMU02053.HTM



Note regarding previous versions:

The "HTML Root Folder" constant was introduced in 4D v11 SQL and does not exist in previous versions of the software. Therefore this code needs to be tweaked in order to work in previous versions.