Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

The apprentice tries to dust off and improve some unused skills...

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:

#!/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(); }

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?

I've checked the 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.)

Details, if they're relevant, include Apache 2.0, Perl 5.6.1, CGI.pm 2.93

Thanks in advance...

--f


In reply to CGI Redirect with Status by footpad

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (3)
As of 2024-04-20 08:23 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found