Created
December 13, 2020 17:13
-
-
Save himanshuahuja96/fc23f84fab48c7f5b3bf1a490049e323 to your computer and use it in GitHub Desktop.
WordPress Redirect to New domain from old using php
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_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