5 Aug 2009, 1:12pm
php:

leave a comment




  • Simple redirection using PHP and HTML meta tag

    Some­thing every­one needs once in a while… maybe you moved a file on your server or you did not install word­press in the root folder of your web­server — like I did nei­ther ;) — a redi­rec­tion or for­ward­ing can be an easy answer.

    The script is rather sim­ple — it redi­rects in three ways to pro­vide a rea­son­able fall back if any of the auto­matic redi­rect­ing fails. To use it on your server, just enter the URL/address/file name/folder you would like the user to be redi­rected to in the sec­ond line of the page/script.

    Put the whole code and markup in a file with file exten­sion “.php”.
    In my case, every user end­ing up at “www.svenbuschbeck.net” should to be for­warded to “www.svenbuschbeck.net/wordpress/home”. So I adjusted the script below like “$url = ‘wordpress/home’”, named the file “index.php” and put it in the root folder. Done :) .
    <?php
    $url = 'put your URL between the parenthesis';
    header("Location: $url");
    ?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"/>
    <meta http-equiv="refresh" content="0;url=<?php echo $url; ?>"/>
    <title>You will be redirected... </title>
    </head>
    <body>
    If you are not redirected automatically, please click <a href="<?php echo $url; ?>">here</a>.
    </body>
    </html>
    *name

    *e-mail

    web site

    leave a comment