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

given input from a form, i need to redirect the users browser to a pre-determined url.

Normally I would do that with the: print "Location $url\n\n";
however, that returns an error when the url specified is a local file. What is the proper way to redirect to a local file on the machine? (both text and executable).

Replies are listed 'Best First'.
•Re: redirecting to a local file
by merlyn (Sage) on May 14, 2003 at 15:40 UTC
    You can't redirect to a non-location. You have to specify a location, so you'll have to move your file under the docroot somewhere.

    There's no requirement that it be a published URL, however. Just beware... if you redirect to a nonexisting URL, the URL is revealed in the standard 404 message, so be careful if that might hint at other nearby URLs.

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

Re: redirecting to a local file
by Thelonius (Priest) on May 14, 2003 at 15:58 UTC
    If by "local file" you mean a file on the client's machine, you can use the "file:" url scheme:
    print "Location: file://c|/testfile.txt\n\n";
    Will redirect the browser to c:\testfile.txt
      I tried that, but IE is printing "server not found" and Mozilla is displaying a "Your page has move here" error page.

      very strange. It used to work.
        Are you sure you're using the colon after Location as in Thelonius's example?
        print "Location: file://c|/testfile.txt\n\n";
        In your initial question you use print "Location $url\n\n";

        Just checking that hasn't been overlooked!