Creating Pseudo Forwarding Areas - the Easy Way!By Joe Bennett
Unless you spent considerable time on the planning of your Web site's physical file structure, chances are you have important areas of the site buried in deep URLs. For example, perhaps a main section on your Web site is a job board type section, which may be located at:
Wouldn't it be nice if you could provide an alternate URL, like:
Well, you can, quite easily, and in this article, I'll look at how to accomplish this technique without
having to create actual directory entries in your Web site!
Furthermore, this technique can be used if you run a site with user accounts where each user has a customized
section to provide customized URLs like:
http://www.yourserver.com/Username/ that could
redirect to, say:
The first thing that needs to be done to implement this technique is to build a custom 404-error page. (If you are unfamiliar with how to build a custom 404 error page, be sure to read: Creating a Custom 404 Error Page.) Name this custom 404 error page anything you want, but make sure that it is an ASP file (in my example I will use
Understand that the HTTP 404 error occurs when the user requests a page that does not exist. This custom
404 error page can do anything a regular ASP page could do. So, when a user visits one of our "customized,"
nonexistent pages, like
http://www.yourserver.com/jobs/, we'll have the 404 error page issue a
|Custom 404 Error Pages on a Hosted Account...|
|If you are using a hosted account you will need to contact the host and have them point the 404-error to your specified ASP 404 error handling page. For my personal account, they pointed to my 404-error page in an hour, for free. Your mileage may vary, though.|
Writing our Custom 404 Error Page
Now that the server is pointing to our
404.asp file it's time to add some script to make it all work!
Realize that when the user enters an invalid URL, he is redirected to our specified custom 404 error page
along with the URL the user attempted to enter. This important information is appended to the QueryString
in the form:
404;complete URL entered by user. Therefore, in our custom 404 error page we
need to first grab the QueryString to find out where the user needs to be sent. We can grab the URL the user
attempted to enter with the following statement:
This line reads the 5th through last characters in
Request.QueryString into the
strRedirect, which, essentially, grabs the complete URL entered by the user.
Specifically, we are using the
Mid function to chop off
404; from the QueryString
and converting everything to lowercase.
Now that we know the URL the user entered, we can redirect them to the proper page. There are a number of ways to do this. One is to hard code in the redirect values, like so:
Notice that you can redirect users to any type of file (HTML, ASP, TXT, etc.).
In the above example you can see that if a user entered
http://www.axdo.net/4guys into their
browser's location window they would be directed to
to reach the media center search, users would only need to enter:
Also note how in the
http://www.axdo.net/Username example, the username entered after the
last forward slash is read into the variable
Username and then appended as the QueryString value
in the subsequent
Finally, notice that you should add a redirect for a regular 404-error page under the
statement, in case the user does enter a nonvalid URL.
Another way to store the redirect values is in a database. A simple database table with two columns:
RealUrl could be constructed. Then, when a user hit the 404 error page,
a quick lookup could be performed to see if the user's entered URL was found in a
in the table; if it was, the user could be automatically redirected to the value in
This technique would be easier to manage, especially if you planned on having a large number of pseudo URLs
that could be redirected to real ones.
Another use of this technique could be used to predict common misspellings in order to proactively reduce the number of 404 errors. What I mean by that someone confounded statement, is that if your site had a URL that was, say:
http://www.yourserver.com/Tutorials, you could add entries to catch common spelling mistakes,
http://www.yourserver.com/Tutorialss. All of these would then just redirect to:
The technique presented in this article illustrates how to create several pseudo forwarding sections on your Web site. Creating such a forwarding system doesn't require that much work - just a custom 404 error page! Furthermore, these forwarding areas can be used to create customized direct links for important areas on your site, for users expecting customized content, or for catching commonly misspelled words to proactively reduce the number of 404 errors. I hope you find this technique useful and decide to implement it in your site!