Forums

[How-To] PHP Redirect script (1 post)

  1. sjefen6
    Member
    Posted 1 year ago #

    I have been looking for a PHP code snippet to make some really good 301 Moved Permanentlys. I used this when changing host and domain.
    file index.php:

    <?php
    $newDomain = "http://www.example.com/blog"; //Leave out the trailing slash
    $requestedPage = $_SERVER['REQUEST_URI'];
    header("HTTP/1.1 301 Moved Permanently");
    header("Status: 301 Moved Permanently");
    header("Location: $newDomain$requestedPage");
    header("Connection: close");
    exit(0);
    ?>

    This makes shure that no links break (assuing you have the same rewrite rules in wordpress). It allso avoids issues with host specific .htaccess rules (I had some).

    Sorry if this is a dup, or oftopic. Did some googleing without finding anything like it so I put it together form 2 different scripts.

Topic Closed

This topic has been closed to new replies.

About this Topic

  • RSS feed for this topic
  • Started 1 year ago by sjefen6
  • This topic is not a support question
  • WordPress version: 3.0.4