-
-
Save taras/aadfb65c1386a162afbef43695788e4f to your computer and use it in GitHub Desktop.
MU-Plugin for WordPress to redirect from non-www to www domain
This file contains hidden or 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 | |
if ( ! preg_match( '#wp-json#', $_SERVER['REQUEST_URI'] ) && ! preg_match( '#wp-content#', $_SERVER['REQUEST_URI'] ) && ! preg_match( '#^www.#', $_SERVER['HTTP_HOST'] ) ) { | |
$https = 443 === $_SERVER['SERVER_PORT'] ? 's' : ''; | |
header( "Location: http{$https}://www.{$_SERVER['HTTP_HOST']}", true, 301 ); | |
die(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You can collapse the first line down to this: