in reply to Perl Redirect - Complete Perl Newbie

If the code you're trying is the one you're showing us, taking a look at the error_log will probably tell you something along the line of Undefined subroutine redirect called at redirect.pl line 8 (and probably the same for the param() sub). To properly import the function interface from CGI.pm, you have to use CGI ':standard'; (or use CGI qw(:standard); as is often seen).

Then, you should use strict;, use warnings;, as well as redirect errors and warnings to your browser while developping with use CGI::Carp qw(fatalsToBrowser warningsToBrowser);. When setting your variable from the CGI parameter 'shop', you'd better do it as my $shop = lc(param('shop')). This has the advantage of standardizing the case, so to speak, as well as making $shop equal to the empty string in case param('shop') is undefined, avoiding some warnings with the following tests.

  • Comment on Re: Perl Redirect - Complete Perl Newbie

Replies are listed 'Best First'.
Re^2: Perl Redirect - Complete Perl Newbie
by Tomster (Initiate) on Feb 11, 2005 at 11:32 UTC
    Thanks for the tips, some error messages on screen would be helpful. I'm still getting the http 500 error. Have I set it up incorrectly? There are other perl scripts running on the server?

      The following code works perfectly here.

      #!/usr/bin/perl use strict; use warnings; use CGI qw(:standard); use CGI::Carp qw(fatalsToBrowser warningsToBrowser); my $shop = lc(param('shop')); if ($shop eq "rg") { print redirect('https://www.planetdistribution.co.uk/store/index.p +hp?cPath=6'); } elsif ($shop eq "ps") { print redirect('https://www.planetdistribution.co.uk/store/index.p +hp?cPath=1'); } elsif ($shop eq "sk") { print redirect('https://www.planetdistribution.co.uk/store/index.p +hp?cPath=19'); } elsif ($shop eq "smm") { print redirect('https://www.planetdistribution.co.uk/store/index.p +hp?cPath=9'); } else { print redirect('https://www.planetdistribution.co.uk/store'); }

      HTTP Error 500 is an Internal Server Error if I'm not mistaken, so the problem lies in your web server configuration. As always, check the error_log.