Skip to content

Instantly share code, notes, and snippets.

@k4zuki02h4t4
Last active August 29, 2015 14:12
Show Gist options
  • Save k4zuki02h4t4/4ff95935abc5d01bde8b to your computer and use it in GitHub Desktop.
Save k4zuki02h4t4/4ff95935abc5d01bde8b to your computer and use it in GitHub Desktop.
WordPress Simple 301 Redirect.
function http_host_301_redirect() {
$site_host = parse_url( get_bloginfo('url', 'raw' ) );
$site_host = $site_host['host'];
$http_host = $_SERVER["HTTP_HOST"];
$redirect = ( empty( $_SERVER["HTTPS"] ) ? "http://" : "https://" ) . $site_host . $_SERVER["REQUEST_URI"];
if ( $site_host === $http_host || !wp_http_validate_url( $redirect ) )
return;
wp_redirect( $redirect, 301 );
}
add_action( 'template_redirect', 'http_host_301_redirect', 0 );
@k4zuki02h4t4
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment