[How-To] PHP Redirect script
-
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 = "https://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.
- The topic ‘[How-To] PHP Redirect script’ is closed to new replies.