Previous: CGI Scripts and Programs Contents and Introduction Next: Using the Search Engine

Flexible redirections

Introduction

Redirections of non-existing pages to existing pages can easily be configured within your web site. This also includes the presentation of the list of available languistic versions of a page in case the requested version does not exists.

How it works

When a non existing page is requested on the server, the webserver calls a program that will analyse what can be done depending of rules present in configuration files.

The program will look for a _redirect.cfg file in the directory of the requested address. If not found, the program will recursively scan the parents directories until it finds a _redirect.cfg file.

The _redirect.cfg file tells the program how to map the requested address to a new address with rules. If none of the rules matches the requested address, the program will try to find a matching rule in the _redirect.cfg of the parent directory tree.

When the first matching rule is found, the program will optionnaly present a page - based on a template - that will show the requested address and the new computed address. This would help the users to update their bookmarks.

An optional automatic timed redirection can be programmed as well.

Configuring the _redirect.cfg file

The _redirect.cfg is a text file with rules on separated lines.

Each line contains 3 columns representing a rule.

The first column is a regular expression that the program tries interpret according to the requested address (URL) . If the rule matches the address then the program will redirect the browser to the page given in the second column.

The second column is thus the new address to which the browser will be redirected.

The third column is a code that tells the behaviour of the program:

Sample _redirect.cfg file

Configuring the _redirect.htm template

The _redirect.htm template is used to present the user with a text showing the requested address that doesn't exists anymore and the new computed address. This should help the user to update locally stored bookmarks.

The _redirect.htm template file should be placed in the same location as the _redirect.cfg file

The _redirect.htm template file is a standard IPG-compliant HTML file with special tags that will be replaced by the program before beeing displayed to the the browser:

An optional text can also be placed between the following tags: <!--AUTOSTA--> and <!--AUTOEND-->. This text will be displayed when an automatic timed redirection is requested.

Sample _redirect.htm template file

	<HTML>
	  <HEAD>
	    <TITLE>Page not found</TITLE>
	    <BASE HREF="http://europa.eu.int/comm/agriculture/_redirect.htm">
	  </HEAD>
	  <BODY>
	  <CENTER><H1>Welcome to the European Commission</H1></CENTER>
 	  <CENTER><P>The page you have requested:</P>
	  <P><!--OLDURL--></P>
	  <P>is not available, or has been moved. You should try:</P>
	  <P><B><!--NEWURL--></B></P>
	  <!--AUTOSTA-->
	   You will be redirected to the new address in a few seconds 
	  <!--AUTOEND--></CENTER>
	  </BODY>
	</HTML>
	

Configuring the linguistic templates (lang_template_xx.htm in the example)

Sample linguistic template

Data Centre