Frontier Tutorials / Writing an ObjectNotFoundHandler / Mode 2 Example

Mode 2 Example

A redirect is accomplished by calling mainResponder.redirect or by throwing a redirect scriptError (generally faster).

Your script could either redirect to a fixed, hardcoded URL or calculate the new URL based on the values of lastNomad and remainingPath.

This is the simplest way for the ObjectNotFoundHandler script to work.

The Example

In this example, we will redirect to a page-not-found page with a site search form.

Create the Script and the Reference

In your #tools table, create a script called "PageNotFoundRedirect". It should look like this:

on PageNotFoundRedirect()
space picturelocal
space picturepageTbl = html.getPageTableAddress()
space picturelastResolvedAdr = pageTbl^.lastNomad
space pictureremainingPath = pageTbl^.remainingPath
space picturenewUrl = "http://" + pageTbl^.host + "/onfhTutorial/pageNotFound"
space picturescriptError( "!redirect " + newUrl )

At the top level of your site, set the value of "#objectNotFoundHandler" to the address of your new "PageNotFoundRedirect" script. PageNotFoundRedirect is now your objectNotFoundHandler script.

Again at the top level of your site, create a new wptext entry named "pageNotFound", with the following contents:

#title "Page Not Found"
<h1>{title}</h1>
<p>We're sorry, the page you requested was not found.</p>
<p>You may have mis-entered the URL.
If not, you may be able to find the page you want via the "Site Outline"
or via the search form below.</p>
<p>
{string( forms^.search )}

Now go back to your browser and reload the page ("http://localhost/onfhTutorial/notThere"). Your page should resemble the following:

PageNotFoundRedir picture

Your "page not found" page can be as simple or complex as you like.

Now on to the Mode 3 example.

Tutorial Contents
Writing an ObjectNotFoundHandler
ONFH Overview
ONFH Modes of Operation
About The Examples
Mode 1 Example
Mode 2 Example
Mode 3 Example
Mixing Modes
Misdirected URLs
ONFH Summary
ONFH Applications
ONFH Resources
Bonus: The "Penultimate" Master Script
Bonus: Mode 3 Utility Script
About the Author