404 Trap core
The core of the 404 Trap is parsing the environment variables to figure out what the user is looking for and then display that data. I have a few different ways that I have been doing this over the years, but I really have settled on one way in particular. I design my sites so that they all have a root directory that describes the area of the sites that the user is browsing. In this case right now, you are in the /blogs/ root area. By using the forward slashes as delimiters (I’m starting to get technical here) I use the request_uri variable as a list. The first item on this list will always describe the root area the user is browsing. The 404 Trap then uses the root area name to call the correct script to handle all the content for that root area, in this case blogs. The base script that handles the root area will then look at the request_uri variable as a list and figure out how long it is. In the case of these blogs it can be 1, 2 or 3 variables in length. The base script then uses a simple switch/case statement to call the correct script based on the length of the request_uri list. If there is only one variable then it shows the overall summary of the blogs. When there are two variables it will use the second variable as a date field and only show the blog entries for that date. With Three variables the script will take the third variable and use that as the ID of the blog in question. Some of my 404 Traps get a bit more complicated than that, but the basic principles are the same. A custom error script calls different scripts based on the data presented in the request_uri variable.






