I am closing my previous site so i want to redirect old domain's homepage & all posts to new domain's homepage. I tried using Cpanel redirect but it only redirects homepage not posts. I want to redirect all posts also. Any solution ?


There are many useful threads on StackOverflow on how implement this, but here's a small WP solution that you can apply without modifying your .htaccess file:

add_action('init', function() {

    $redirect_to_domain = 'google.com'; // without protocol
    $https = false; // redirect to https ( default: http )

    // don't change the following unless you know what you're doing
    $domain = str_replace( array('http://', 'https://'), '', get_site_url() );

    wp_redirect( ( $https ? "https://" : "http://" ) . str_replace( $domain, $redirect_to_domain, $uri ) );


Remember, WordPress will still be initiated until the redirect is performed.

Hope this helps.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.