Skip to content

Instantly share code, notes, and snippets.

@himanshuahuja96
Created December 13, 2020 17:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save himanshuahuja96/fc23f84fab48c7f5b3bf1a490049e323 to your computer and use it in GitHub Desktop.
Save himanshuahuja96/fc23f84fab48c7f5b3bf1a490049e323 to your computer and use it in GitHub Desktop.
WordPress Redirect to New domain from old using php
<?php
function redirect_to_new_domain(){
if( (strpos($_SERVER['HTTP_HOST'], 'domain.com') !== false) || (strpos($_SERVER['HTTP_HOST'],'www.domain.com')!== false) ){
wp_redirect( 'https://www.new-domain.com'.$_SERVER['REQUEST_URI'] , 301);
exit;
}
}
add_action("init","redirect_to_new_domain");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment