General Information
Missouri State uses a custom 404 page to manage redirection on all central servers. This page is provided to help explain the concepts used by the system. Missouri State uses Microsoft IIS and ASP/ASP.Net pages, but there is nothing specific to these technologies. The same techniques outlined here could be applied to different hosting environments.
Basic Redirection Theory
We support 3 types of redirections: exact match, file and directory. These types are more descriptive of the destination rather than the requesting address.
Exact Match
The easiest redirection. In this case a specific file is moved from one location to another. Example:
Requested URLs | Destination URLs |
---|---|
http://www.missouristate.edu/admissions/admissioncalculator.asp | https://www.ws.missouristate.edu/admissions/calculator.aspx |
File Redirections
This type of redirection is used when the relative structure of a site changes and you want any addresses for the site. In this case the user tries to access a specific page that no longer exists, but rather than giving them a 404 page, they are redirected to a new homepage. An example usage of this type is when our computer policies were reorganized. Rather than having the old pages give 404 errors, we opted to have any address requested from that site take the user to the new computer policy homepage.
Requested URLs | Destination URLs |
---|---|
http://www.missouristate.edu/oit/web.asp http://www.missouristate.edu/oit/email.asp |
http://www.missouristate.edu/ais/InfoTech.htm |
Directory Redirections
This type of redirection is used when a site and it’s relative substructure is moved intact to a new location. Old files are mapped to their new location. This is used frequently for department name changes and server moves.
The Custom 404 Page
This page receives a requested URL that doesn’t exist on the server, parses the address into it’s parts (server/host, virtual path, querystring, etc), looks for a match in the database and then either redirects the client to the new address or displays the 404 page. The actual work of the page is done by calling an SQL stored procedure. If the procedure returns a recordset, the first record will be the most relavent match. If the recordset is empty, there is no match and the 404 page is displayed.
The Database Structure
For the ASP code and stored procedure to make sense, use the following database structure as a reference.
Hosts are mapped to a list of all known aliases. All redirections are mapped to every possible alias for the given virtual server.
Example Data
Hostname Table
host_id | hostname |
---|---|
1 | www |
1 | www.missouristate.edu |
1 | missouristate.edu |
Host Table
id | primary_hostname |
---|---|
1 | www.missouristate.edu |
Redirection Table
id | host_id | vpath | NewURL | type_id | DateAdded |
---|---|---|---|---|---|
1 | 1 | /admissions/admissioncalculator.asp | https://www.ws.missouristate.edu /admissions/calculator.aspx | E | 10/4/2006 |
2 | 1 | /oit | http://www.missouristate.edu/ais/InfoTech.htm | F | 10/20/2006 |
3 | 1 | /acadaff | http://www.missouristate.edu/provost | D | 9/19/2005 |
Match_Redirects Stored Procedure
This stored procedure does the real work of the whole process. It takes a hostname and virtual path as arguments and returns a list of matches sorted by relavency. Longer virtual path matches are considered to be more specific and therefore more relavent.
CREATE PROCEDURE [dbo].[match_redirects] @reqhost varchar(100), @reqpath varchar(500) AS
SELECT r.vpath, r.NewURL, r.[type_id] AS [Type]
FROM redirection r INNER JOIN hostname hn ON hn.[host_id] = r.[host_id]
WHERE UPPER(hn.hostname) = UPPER(@reqhost) AND (vpath = @reqpath OR (PATINDEX(vpath + ‘/%’, @reqpath) <> 0))
ORDER BY LEN(vpath) DESC
Conclusion
The redirection management technique outlined in this page has been in production use by Missouri State University since the late 1990s. It was initially developed to handle a server reconfiguration and has since become a core application for our centrally hosted files. We have found that server upgrades and moves, department name changes, restructuring and many other changes can be easily handled with this application. Entire hosts have been redirected with this single page.
One of the biggest strengths of this system is that a page must not exist in order for the redirection to actually occur. Therefore advance preperation for system changes can include entering all of the live redirections prior to the actual change with the developers safe in the knowledge that only after their content is moved will the redirection take affect.
Discover more from Web Strategy and Development News
Subscribe to get the latest posts sent to your email.