Forum Moderators: coopster & phranque

Message Too Old, No Replies

301 redirect in Perl

on IIS doesn't work

         

aleksl

8:51 pm on Feb 4, 2005 (gmt 0)



Hi guys,

Need a simple perl help. We have one 3rd party script on our site that needs to be updated with a 301 redirect. Similar to this thread:
[webmasterworld.com...]

For instance, when I request somesite.com/page1.cgi , I want script to redirect to someothersite.com/page1.cgi.

But since I am on win2003 and IIS, none of the simple solutions provided on the net work. I've tried all possible combinations of these:

print "Status: 301 Moved permanently\nLocation: [someothersite.com...]
print "Content-type: text/html; charset=utf-8\n\n";
print "Location: [someothersite.com...]

Only last line of code seems to do redirect at all, any others, and I will get a text printed in the browser. That last line does a 302 redirect.

I am stumped. Any ideas?

aleksl

3:01 am on Feb 10, 2005 (gmt 0)



anyone?

moltar

4:06 am on Feb 10, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Try this:


use CGI;
my $q = CGI->new();
print $q->redirect(
-location => 'http://someothersite.com/page1.cgi',
-status => 301,
);

aleksl

9:19 pm on Feb 10, 2005 (gmt 0)



Nope, doesn't work. Similarly to print line mentioned above, just displays this text in a browser (without spaces in URL):

Status: 301
Location: http :// someothersite.com / page1.cgi

?

lexipixel

10:35 pm on Feb 10, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Can you use META refresh in the HEAD of the page?

Where the page at: [somesite.com...]
contains:

<meta http-equiv="refresh" content="0;url=http://www.someothersite.com/page1.htm/">

aleksl

1:14 am on Feb 11, 2005 (gmt 0)



Yes, that is the last resort, I'd like to avoid using it.

moltar

12:27 am on Feb 17, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



If it displays the text in the browser it's probably you already printed content type somewhere before in the script.

aleksl

7:55 pm on Feb 19, 2005 (gmt 0)



No, I actually tried your code in a separate file.
I don't know, there's something about Perl under IIS...not enough time to research.

QuietCat

1:00 am on Feb 20, 2005 (gmt 0)

10+ Year Member



Try renaming your script from page1.cgi to nph-page1.cgi