Penn State

Web Conference 2004

Writing Perl/CGI Scripts for ITS/ASET Web services

HTTP Redirects

<- Back - Web Access Control| Up |Advanced Techniques - Next ->

HTML method of refreshing

Many Web authors are familiar with the HTML meta tag method of redirection. This is passing a tag in the HTML <head> section that instructs the browser to refresh to another page (or the same) after a set delay in seconds. An example is below which redirects the page to http://test.scripts.psu.edu/users/x/y/xyz123/scripts/newscript.cgi after a 10 second delay (set to 0 for an immediate refresh):

<meta http-equiv="Refresh" content="10; url=http://test.scripts.psu.edu/users/x/y/xyz123/scripts/newscript.cgi">

HTTP method of redirecting

HTTP Redirects can be set by the Apache configuration, or from a CGI script, as it set in the HTTP headers. Here are examples using .htaccess and Perl methods of redirecting to the same URL as above:

.htaccess redirect
Redirect /users/x/y/xyz123/scripts/oldfile.html http://test.scripts.psu.edu/users/x/y/xyz123/scripts/newscript.cgi
Perl redirect
#!/usr/local/bin/perl

print "Location: http://test.scripts.psu.edu/users/x/y/xyz123/scripts/newscript.cgi\n\n";
Browser <==HTTP-- Web Server
HTTP/1.1 302 Found
Date: Mon, 14 Jun 2004 03:50:02 GMT
Server: Apache/1.3.6 (Unix)
Location: http://test.scripts.psu.edu/users/x/y/xyz123/scripts/newscript.cgi
Connection: close
Content-Type: text/html

<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<HTML><HEAD>
<TITLE>302 Found</TITLE>
</HEAD><BODY>
<H1>Found</H1>
The document has moved <A HREF="http://test.scripts.psu.edu/users/x/y/xyz123/scripts/newscript.cgi">here</A>.<P>
<HR>
<ADDRESS>Apache/1.3.6 Server at www.clubs.psu.edu Port 80</ADDRESS>
</BODY></HTML>
<- Back - Web Access Control| Up |Advanced Techniques - Next ->

If you have any questions, feel free to ask me - mailto:jcd@psu.edu

Content by: Jeff D'Angelo <jcd@psu.edu> © 2004

Last update on: Sunday, 13-Jun-2004 23:52:02 EDT