Issue with filename containing "-" in PERL
I have created a file called "nph-select.pl" and put code for redirection as below.
#!"D:\xampp\perl\bin\perl.exe" -w
use CGI qw/:standard/;
my $cgi = new CGI;
print $cgi->redirect(-uri => 'http://www.google.com/', -nph => 1);
and executing file then its gives me 302 STATUS message saying "Document has moved here" . But when I am renaming the same file just by removing "-" in it i.e new file name is "nphselect.pl" then it run properly with redirection also. Can anybody suggect what setting I am missing?
My request headers are
Host localhost:8080
User-Agent Mozilla/5.0 (Windows NT 5.1; rv:2.0.1) Gecko/20100101 Firefox/4.0.1
Accept text/html,application/xhtml+xml,application/xml;q=0.9,/;q=0.8
Accept-Language en-u开发者_如何学JAVAs,en;q=0.5
Accept-Encoding gzip, deflate
Accept-Charset ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive 115
Connection keep-alive
And RESPONSE HEADERS are blank.
First, some webservers treat cgi scripts starting 'nph-' differently than any other cgi script, so removing the - will change that.
You are calling redirect incorrectly; CGI's named parameters all must start with -, like this:
print $cgi->redirect(-uri => 'http://perl.about.com/');
With uri
instead of -uri
, it is using positional parameters, so it tries to redirect to 'url' (which your webserver may fully qualify for you).
If you are going to use an nph- script, setting redirect's nph option provides a fuller set of headers; this may resolve your problem:
print $cgi->redirect(-uri => 'http://perl.about.com/', -nph => 1);
精彩评论