cjohnson419 has asked for the wisdom of the Perl Monks concerning the following question:

Hi I'm not a Perl expert, and need some help please. I am currently using a script that redirects using a query after the url. (using question mark).

I want all present links to it to default to url I specify, not the query url. for example, this is how the links look:

http://www.thewebsite.com/cgi-gin/myscript.pl?http://www.redirectedurl.com

I want all of the traffic to that page to go to a default url. It shouldnt be that difficult, right? Here is the present script:

####### Redirection URL $ToUrl = $ENV{'QUERY_STRING'}; &Redirect; ####### Send to url pointed at by the hyperlink sub Redirect { print "Location: $ToUrl\n\n\n"; } ###########

Again, I do NOT want the query to be used. I tried just inserting a url after $ToUrl = but that did not work. Any help greatly appreciated.

Replies are listed 'Best First'.
Re: Redirect Eliminate
by moritz (Cardinal) on Jan 26, 2011 at 10:03 UTC
    Maybe you should not only print a Location header, but also a Status: 302 Found?

    If you're not all that familiar with HTTP, using CGI isn't a bad idea:

    use CGI; print CGI->new->redirect($ToUrl);
Re: Redirect Eliminate
by Corion (Patriarch) on Jan 26, 2011 at 08:04 UTC

    I'm not sure I understand what you want. Do you want to always redirect to a constant URL? Then set your $ToURL to a constant value instead of the query string, and output that:

    $ToURL = 'http://example.com'; ...

      I did that, and it didnt worlk

      ####### Redirection URL $ToUrl = 'http://www.google.com'; &Redirect; ####### Send to url pointed at by the hyperlink sub Redirect { print "Location: $ToUrl\n\n\n"; }

      The web browser reports 404 error.

        A "404" error means that the URL you typed in was not found. This has nothing to do with Perl or your script and everything with how your webserver is set up. Consult with your webserver administrator how to solve this problem.

        I recommend looking in the webserver error log to see if it gives more information about what URL fails.

Re: Redirect Eliminate
by cjohnson419 (Initiate) on Jan 26, 2011 at 08:24 UTC

    this did not work either

    ####### Redirection URL $ToUrl = 'http://www.google.com'; &Redirect; ####### Send to url pointed at by the hyperlink sub Redirect { print "Location: $ToUrl\n\n\n"; }

    getting 404 error on brower. Baffled, Can anyone help</p?