Home Account

redirect php request to secure https host

07-May-2011 21:54:16 dennis

Tags: php scripts-and-functions

In the following example we will direct to a specific host. This can prevent trouble with indexing your site by spiders. Then there is only one host. And any requests will be routed to your choosen host.

<?php

if ($_SERVER['SERVER_PORT'] != 443) {
    $redirect = "https://" . $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI'];
    header("Location: $redirect");
}