Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

cgi redirect

by The_Rev (Acolyte)
on Nov 26, 2002 at 18:48 UTC ( [id://215898]=perlquestion: print w/replies, xml ) Need Help??

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

redirect is working correctly, but does anyone know if its possible to redirect and not have the page displayed in the URL:

I'm using the follwing code:

#!/perl/bin/perl.exe -wT use CGI; $q = new CGI; $name = $q->param('name'); $comment = $q->param('comment'); if ($name =~ /^foo$/i){ print $q->redirect("http://hiddenURL"); } else{ print $q->header("text/html"); }

Replies are listed 'Best First'.
•Re: cgi redirect
by merlyn (Sage) on Nov 26, 2002 at 19:24 UTC
    If it's on a different server, you'll need to fetch the data yourself and proxy it by rewriting all the URLs. I have a column on that, of course.

    If it's on the same server, you can do an "internal" redirect rather than an "external" redirect as you've done. To the browser, nothing has happened. The server is just told via a URL that starts with / instead of http: that it should start over again with a different URL on this server. Again, you have to worry about leakage, and relative URLs, but it's a fairly quick solution and may be exactly what you're looking for.

    -- Randal L. Schwartz, Perl hacker
    Be sure to read my standard disclaimer if this is a reply.

      That does indeed work, but the URL for the specific page is still displayed in the path on the browser...Is it possible to use an internal redirect without the URL changing to the user
        Poor man's solution:
        #!/usr/bin/perl use strict; use warnings; use LWP::Simple my $url = 'http://some.domain/some/path/to/file.htm'; my $content = get $url; $content =~ s|</head>|<base href="$url"></head>|is; print "Content-type: text/html\n\n$content"; exit(0);

        If you want to keep all links internal, it will take a while - especially if you take some time to think about why you want to mis-represent content's origin to users on that large a scale.

        .02

        cLive ;-)

        That does indeed work, but the URL for the specific page is still displayed in the path on the browser
        I'm not sure what you mean. If you put:
        print "Location: /icons/left.gif\n\n";
        at /cgi/leftarrow, it'll run the script and display a left arrow, but the URL will still remain the CGI location. I thought that's what you wanted.

        Actually, you may be running a non-standard web server (something other than Apache). If that's the case, you should disclose that so I stop trying to bring Apache-specific knowledge into the discussion.

        -- Randal L. Schwartz, Perl hacker
        Be sure to read my standard disclaimer if this is a reply.

        I'm not aware how to do this with a CGI-Script. It might be possible with mod_perl, though.

        Take a look at the Apache module mod_rewrite; that should do what you want.

Re: cgi redirect
by dingus (Friar) on Nov 27, 2002 at 10:30 UTC
    If you use The Ultimate Rediector CGI Script that I wrote then you would simply create an XML file somewhere in your webpages diretory tree (i.e. anywhere below $ENV{"DOCUMENT_ROOT"} ) and you get redirected nicely using the url: http://yourserver/cgi-bin/relo.cgi/path/file
    $ENV{"DOCUMENT_ROOT"}/path/file.xml contains: <RELO> <SERVICE NAME='comment' URI='http://hiddenURL' MODE='FRAME' /> </RELO>

    Dingus


    Enter any 47-digit prime number to continue.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://215898]
Approved by tadman
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others taking refuge in the Monastery: (4)
As of 2025-05-20 06:10 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.