Home Account

redirect php request to secure https host

2011-05-07 21:54 dennis iversen

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");
}

This page has been requested 1156 times