Mailinglist Archive: opensuse (4343 mails)

< Previous Next >
Re: [SLE] Redirecting URL with perl
  • From: zentara <zentara@xxxxxxxxxxx>
  • Date: Fri, 1 Nov 2002 19:16:13 -0500
  • Message-id: <20021101191613.45797935.zentara@xxxxxxxxxxx>
On Sat, 2 Nov 2002 00:59:39 +0200
Togan Muftuoglu <toganm@xxxxxxxxxxxx> wrote:

>I would like to redirect the incoming http requests randomly to a
>selective URL. Below is what I thought would do.
>
>#!/usr/bin/perl -w
># Do I need this module ?
>use CGI qw(:cgi);

No, you don't need this unless you want to set a cookie or receive data.

>@URL =("http://susefaq.sourceforge.net";,
> "http://dinamizm.ath.cx";,
> "http://toganm.tripod.com";,
> "http://www.smaug42.com/susefaq";,
> "http://www.bmtsolutions.com/suse_faq";,
> "http://www.jon.fl.net.au/suse/unofficial-faq";,
> "http://www.e-vega.info/susefaq";,
> "http://www.ods.co.cr/susefaq";,
> "http://www.netbulans.com/susefaq";,
> "http://www.wdm.com/susefaq";,
> "http://www.myxdu.com/susefaq";,
> "http://www.tigersden.co.uk/susefaq";);
>
>srand(time |$$);
>$number_of_url=$#URL;
>$random =int(rand($numer_of_URL));
^^^^^^^^^^
$number

>
>$random_URL = $URL[$random];
>
>#We will redirect
>print "Content-type: text/html", "\n\n";

Don't print the Content-type header when you are printing a "location"; otherwise
you will print the next line, instead of redirecting. If you have trouble with windows browsers,
it sometimes helps to print the above line BUT ONLY with 1 "\n".

>
>print "Location: $random_URL\n\n";
>exit;
>
>
>1) First of all is this correct
>2) How do I get it work in the HTML

After you fix those errors, you need to fix your apache server's configuration
to use a perl script as an index.cgi.

There are a couple of ways to do it.
1. Rename the file to index.html and change the section in httpd.conf
2. Name it index.cgi and enable cgi execution in the html directory

# DirectoryIndex: Name of the file or files to use as a pre-written HTML
# directory index. Separate multiple entries with spaces.
#
<IfModule mod_dir.c>
DirectoryIndex index.html index.cgi index.php
</IfModule>

<Files /srv/www/htdocs/index.htm*>
Options -FollowSymLinks +Includes +MultiViews +ExecCGI
</Files>


Do a google search for "index.cgi" for alot of discussion on how to do it.









--
use Perl; #powerful programmable prestidigitation

< Previous Next >
References