Re: redirect.pl sez Content-Type: application/x-perl
On Thu, Oct 31, 2002 at 10:10:52AM +0800, Andrew Shugg wrote:
> > Yeah, but the CGI(3pm) manual page says that that shouldn't be done:
> >
> > The redirect() function redirects the browser to a
> > different URL. If you use redirection like this, you
> > should not print out a header as well.
>
> If you don't use CGI.pm's redirect() then the script just needs to spit
> out the following:
>
> "Content-Type: text/html\nLocation: $url\n\n"
>
> I haven't looked at (don't have access to) the source of the Perl script
> in question, so just gave as many suggestions as I could think of. =)
Here's the script:
#!/usr/bin/perl -wT
# Copyright 1999,2000 James Treacy.
# Permission is granted to use this under the GNU GPL.
# used to select a mirror from the pulldown menu on the www.d.o front page
require 5.001;
use strict;
use CGI;
MAIN:
{
my ($input, # The CGI data
$site);
$ENV{PATH} = "/bin:/usr/bin";
# Read in all the variables set by the form
$input = new CGI;
# If you want, just print out a list of all of the variables.
# print $input->dump;
# exit;
# print $input->header('text/html'); -- not allowed according to CGI(3pm)
$site = $input->param('site');
if ($input->param('page')) {
if ($site =~ /^\w\w$/) {
print $input->redirect("http://www.".$site.".debian.org".$input->param('page'))
} else {
print $input->redirect($site.$input->param('page'))
}
} else {
print $input->redirect($site);
}
}
(Hmm, have to update that copyright... and remove arcane variations...
and scrap it, anyway :)
> > I think I'll experiment with Apache's rewrite rules instead, that seems
> > much, much cleaner.
>
> Won't that require replication of the rules at each Debian web mirror?
No, why? All of the mirrors use cgi.debian.org right now for the
redirections.
> (I'm not exactly sure how you're intending to implement this.)
Along these lines:
RewriteEngine on
RewriteRule ^/cgi-bin/redirect.pl\?page=(.+)&site=(..)$ http://www.$1.debian.org$2 [L,R]
That way we spare the server of forking Perl just to do a redirection,
something that Apache does very well itself already...
What _really_ is the problem here is that I have to handle various
permutations of the URL syntax in the rewrite rule (e.g. ?site=xy&page=/ vs.
?page=/&site=xy etc).I'm likely going to fix this by having the web pages
use a different, more easily parsed syntax. :)
The regex matching in case someone puts crap inside it is also
troublesome... but the example above didn't work anyhow.
--
2. That which causes joy or happiness.
Reply to: