Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

I've recently got a new client and I converted their html files to shtml pages, and everything works great except the 404.shtml that calls on a new .pl file to this portion of the script via <!--#include virtual="cgi-bin/check.pl" -->
here's the snip from the check.pl file
$page=$ENV{'REQUEST_URI'}; if ($page =~ /a\.html/) { $p="a.shtml"; } elsif ($page =~ /b\.html/) { $p="b.shtml"; } elsif ($page =~ /c\.html/) { $p="c.shtml"; } elsif ($page =~ /d\.html/) { $p="d.shtml"; } else { print header( -Refresh => "5; URL=http://foobar.com"); if ($p) { print header; printnewsite(2, $p); } else { printnewsite(1); }

If I use the "header( -Refresh" method, the script does not refresh through the shtml, but is ok if I go to it directly.
If I use the start_html(-head=>meta({-http_equiv => 'Refresh', -content=> '5; URL=http://someurl//thiscode.pl'})); it will work ok either way; however, I've allready established a set of html, head, title, and body tags for the printnewsite(); sub, so I get two sets when i use print start_html(); which is not a good thing.
I've also used the print redirect();, it fails just like the header(-refresh.
Is there something I can do that will work with an shtml or am I missing something else here?
Thank you in advance.

Replies are listed 'Best First'.
Re: Redirection Failure from SHTML
by friedo (Prior) on Feb 11, 2005 at 17:19 UTC
    CGI's header() method is for sending HTTP headers, not meta HTTP tags. To send an HTTP redirect, you can use:

    header(-location => 'http://foobar.com/');

    Note that the HTTP standard does not have a timing feature; if you send the redirect the browser will go there right away.

    If you use it from within an SSI, be sure that it's executed before anything else in the file, as mod_include will send default headers as soon as it encounters some data to send. (I think there may be a way to suppress this behavior, however. Check the mod_include docs.)

      I've used the header to print out Meta tags. That code with the meta worked just fine.
      I did use what you suggested and I got an error: "[an error occurred while processing this directive]" and yes the script was the first thing to send out. I dunno what else it could be. I guess I'll scrap it and work it another way...

      Uh, just FYI, meta tags began life as a way to specific information that was supposed to be in the HTTP response header within the document instead.

      Makeshifts last the longest.