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

I want to automatically redirect users that go to my old web site to a perl script on my new website. I have three old sites so I want to pass variables to the perl script so I know were a visitor is coming from. I know I could put a simple html page on my old sites that displays a message that I've moved and a link the visitor could click to execute the Perl script on the new site. However I would prefer to skip the link and go directly from the old index.html to the Perl script if this is possible. Thanks for any help.
  • Comment on How to redirect an html page to a Perl script

Replies are listed 'Best First'.
Re: How to redirect an html page to a Perl script
by bbfu (Curate) on Sep 28, 2003 at 21:59 UTC

    If you can arrange it, you'd be best off having your server return a 301 Moved response code. This is the preferred solution.

    If you don't have the access to do that with your server, you could replace your index.html file with a message saying it's moved, and including a meta refresh tag, like so:

    <html> <head> <meta http-equiv="refresh" content="0; URL=http://new.site.com/script.pl?source=old+sit +e+name"> <title>Page has moved!</title> </head> <body> <h1>This page has <a href="http://new.site.com/script.pl?source=old+site+name">mov +ed</a>! </h1> </body> </html>

    Of course, meta refresh isn't supported by all browsers (IIRC, lynx doesn't support it). And it might screw with the browser's history.

    Update: Fixed content portion of meta refresh (missing URL=), and added some more explanation.

    bbfu
    Black flowers blossom
    Fearless on my breath

Re: How to redirect an html page to a Perl script
by Nkuvu (Priest) on Sep 28, 2003 at 22:03 UTC
    I use something like this:
    <html> <head> <meta http-equiv="Refresh" content="0; URL=new_page.htm"> </head> </html>
    and it works just fine.

      Since not all browsers support meta refresh, you should probably include a message saying that your site moved, and a link.

      bbfu
      Black flowers blossom
      Fearless on my breath

        Well yeah maybe. Or maybe I don't want visitors who don't have a meta-refresh-enabled browser to be able to visit my new site. ;)

        No, you're right, it was an oversight on my part, since I've never given it extensive thought.

Re: How to redirect an html page to a Perl script
by Theo (Priest) on Sep 29, 2003 at 19:33 UTC
      I have three old sites so I want to pass variables to the perl script so I know were a visitor is coming from.

    I don't remember the correct terms for this, but the header your perl script will get from your old web sites will contain information about which URL sent the visitor to you. Perhaps it's called "HTTP Referer" or somesuch. That may contain enough info to tell you where your visitor is coming from.

    -theo-
    (so many nodes and so little time ... )
    Note: All opinions are untested, unless otherwise stated