Welcome to WebmasterWorld Guest from

Forum Moderators: coopster & jatar k & phranque

Message Too Old, No Replies

Perl-Cgi redirection using Apache webserver

8:46 am on May 14, 2009 (gmt 0)

New User

5+ Year Member

joined:May 11, 2009
posts: 6
votes: 0


I am stuck into a small issue. I am just simply trying to redirect to a different page if the batch file runs successfully thru system command. success_Calc.html is stored in cgi-bin folder and htdocs folder of the apache server. I have searched the net and tried the below commands but redirection ceases to work. It just prints the URL on the web browser. Are there any config file setting required for this on Apache server?

my $res=system ("test.bat");
if ($res==0){
$cgi-> redirect('http://servername:port/cgi-bin/calc_success.html';}

#{print 'Status: 302 Moved', "\r\n", 'Location: http://servername:port/htdocs/calc_success.html', "\r\n\r\n";}

#{print "Location: http://servername:port/htdocs/calc_success.html$ENV{'REQUEST_URI'}";}

#{ print redirect(-uri=>'http://servername:port/calc_success.html',
# -nph=>1,
# -status=>301);}

I have also tried calc_success.pl which is again a perl file with some HTML tags in it.

the URL is accesible with the browser and there are no errors in Apache error log.

Any pointers will be appreciated

Thanks in Advance!

9:40 am on May 14, 2009 (gmt 0)

Junior Member

5+ Year Member

joined:Dec 20, 2008
votes: 0

the cgi-bin is generally setup to not respond to requests for stuff like html pages, so that is probably the problem there. If the html document is in the htdocs folder you don't include that in the URL, its just the www root folder generally so you just use the doamin name and the file name:

$cgi-> redirect('http://servername/calc_success.html');

assumes you have loaded the CGI module and created the $cgi object.

Note the syntax errors in your posted code.

4:10 am on May 15, 2009 (gmt 0)


WebmasterWorld Administrator phranque is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:Aug 10, 2004
votes: 13

welcome to WebmasterWorld [webmasterworld.com], gsarin!

you are probably going to have to name it as a .cgi file and/or configure apache to activate cgi scripts with that file extension using AddHandler Directive [httpd.apache.org].