Skip to content

Instantly share code, notes, and snippets.

@shadowhand
Created January 17, 2009 16:14
Show Gist options
  • Save shadowhand/48378 to your computer and use it in GitHub Desktop.
Save shadowhand/48378 to your computer and use it in GitHub Desktop.
<?php
$protocol = empty($_SERVER['HTTPS']) ? 'http' : 'https';
$domain = $_SERVER['SERVER_NAME'];
$path = $_SERVER['REQUEST_URI'];
if (strpos($domain, 'www.') === 0)
{
// Remove the www from the domain
$domain = substr($domain, 4);
}
header('HTTP/1.1 301 Moved Permanently');
header("Location: {$protocol}://{$domain}{$path}");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment