1
votes

I have a WordPress site with 200+ blog posts and 25 pages. Now I want to move my blog posts(not pages) to new WordPress with sub-domain blog.sitename and setup 302 redirections just for the posts. I know how to move the posts the o new site. But I don't know how to setup 302 redirection just for the blog posts (Manually setting redirection for 200+ posts will ba real pain).

So does anyone know an easy way to make the pages load from the main site but whenever a blog post url is called it will do a 302 redirect to sub-domain

1

1 Answers

0
votes

You can use function file to add new action hook to do this as per below given example.

add_action( 'template_redirect', 'wpse_blog_redirect' );

function wpse_blog_redirect(){
     if ( is_single() && 'http://blog.example.com' !== $_SERVER['HTTP_HOST'] && 'post' === get_post_type() ){
        wp_redirect( 'http://blog.example.com' . $_SERVER['REQUEST_URI'] );
        exit;
     }
}