Skip to content

Instantly share code, notes, and snippets.

@mikeschinkel
Last active August 8, 2016 06:10
Show Gist options
  • Save mikeschinkel/0f911382bb5a3b416764b3113ea79d54 to your computer and use it in GitHub Desktop.
Save mikeschinkel/0f911382bb5a3b416764b3113ea79d54 to your computer and use it in GitHub Desktop.
MU-Plugin for WordPress to redirect from non-www to www domain
<?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