<?xml version="1.0" encoding="windows-1252"?>
<node id="263134" title="CGI Redirect with Status" created="2003-06-04 15:51:22" updated="2005-08-03 09:30:57">
<type id="115">
perlquestion</type>
<author id="33117">
footpad</author>
<data>
<field name="doctext">
&lt;P&gt;&lt;I&gt;The apprentice tries to dust off and improve some unused skills...&lt;/I&gt;&lt;/P&gt;

&lt;P&gt;I'm creating a 404 ErrorDocument handler to perform redirects based on file name changes on my site's source files.  Here's an abbreviated version of what's currently working:&lt;/P&gt;

&lt;code&gt;#!/usr/bin/perl -wT
use strict;
use CGI qw(:standard);
$| = 1;

my $cgi = new CGI;
my $dir = '/my/httpd/path'; # spoofed
my $old = $ENV{ 'REDIRECT_URL' } || '';
my $new = '';

if ( $old =~ /(.*?)\.foo/i )
  { 
    $new = "$1.bar";
    if ( -e "$dir$new" ) 
    { 
      print redirect( $new );
      exit;
    }
  }
else { doStandard404(); }&lt;/code&gt;

&lt;P&gt;My petition is, "Is there a way to set the status code of the redirection?"  (The idea, as you might expect, is to return a 301 indicating that the document has moved permanently, so the search engines will notice the change and update their databases accordingly)  Alternatively, does CGI.pm already return an appropriate error code?&lt;/P&gt;

&lt;P&gt;I've checked the [http://www.perldoc.com/perl5.8.0/lib/CGI.html|Friendly Docs], but didn't see anything.  Also, a few google searches didn't turn up anything that seemed relevant, though may be due to my lack of [tilly]-fu.)&lt;/P&gt;

&lt;P&gt;Details, if they're relevant, include Apache 2.0, Perl 5.6.1, CGI.pm 2.93&lt;/P&gt;

&lt;P&gt;Thanks in advance...&lt;/P&gt;

&lt;P&gt;&lt;I&gt;--f&lt;/I&gt;&lt;/P&gt;</field>
</data>
</node>
