Last active
August 8, 2016 06:10
-
-
Save mikeschinkel/0f911382bb5a3b416764b3113ea79d54 to your computer and use it in GitHub Desktop.
MU-Plugin for WordPress to redirect from non-www to www domain
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function redirect_to_www() { | |
if ( ! preg_match( '#^www.#', $_SERVER['HTTP_HOST'] ) ) { | |
$https = 443 === $_SERVER['SERVER_PORT'] ? 's' : ''; | |
header( "Location: http{$https}://www.{$_SERVER['HTTP_HOST']}", true, 301 ); | |
die(); | |
} | |
} | |
redirect_to_www(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment