Redirect a site to HTTPS using PHP
This PHP script will redirect web site visitor to HTTPS (SSL) url. You can add this in your index.php of the web site
1 2 3 4 5 6 |
if (empty($_SERVER['HTTPS']) || $_SERVER['HTTPS'] != "on" ) { header("HTTP/1.1 301 Moved Permanently"); $newUrl = "https://" . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']; Header("Location: $newUrl"); exit; } |
Move a site to new URL using PHP
1 2 3 4 |
$newUrl = "https://NEW-URL-HERE" . $_SERVER['REQUEST_URI']; header("HTTP/1.1 301 Moved Permanently"); Header("Location: $newUrl"); exit; |
You can also use Apache mod_rewrite .htacess to do the redirection.