2

How to redirect Old Post URL to new Post URL and keep Old post Comments? is it possible. can any one give me plugin to do this.

1
  • if you use a 301 htaccess redirection you won't need a plugin and all comments will stay
    – Core972
    Jun 14 '18 at 8:34
1

I use is free redirection plugin. If you are using Yoast SEO premium, redirection feature is available for you already. You can also use any other plugin if you like. The only thing you need to ensure is, it should be a 301 redirection.

For this example, I’m using Redirection plugin.

Here is the scenario:

Already published post with URL: https://WPSutra.com/how-to-add-google-amp-to-wordpress-to-speed-up-your-mobile-site
New URL After editing the post slug: https://WPSutra.com/Google-amp-WordPress

Go to Tools > Redirection (or redirection tab of any other plugin that you are using). You can also set redirection using the .htaccess method.

Here you can set the 301 redirect from old post to the new one as shown in below screenshot: enter image description here

What this would do is, when someone will click on your old URL, they will be automatically redirected to new URL. This would ensure you wouldn’t lose any traffic after changing post slug of the already published post.

Do note that you would lose your social media shares number & that is a very little trade-off you need to make when dealing with editing old post URL. I usually do this for editing my old blog posts or dealing with non-performing blog posts.

2
  • Great, but... How is this an answer? You don't even mention comments in your post... Jun 14 '18 at 5:32
  • yes i use same plugin but previous post comments are not redirected to new post
    – Harsha
    Jul 2 '18 at 12:04
0
<?php
/* If your Old Website Blog indexed on google crawling site & you want to replace your URL with New One,
Here, I describe whole process. */
// Redirected Single Blog Posts using "template_redirect" function without use of "301 Redirection" plugin
/* Redirected Blog detailed page URL like : 
"HOMEURL/test-abc" to "HOMEURL/resources/blog/test-abc" */

/* Start Template Redirection Only For Single Blog Posts */
add_action('template_redirect', 'redirect_single_post_func');

function redirect_single_post_func() {
    if (is_singular('post')) {
        global $post;
        global $wp;
        $resource_ID = 'Your Page/Posts ID'; //specify id here
        $resource_post = get_post($resource_ID);
        $resource_slug = $resource_post->post_name;

        $blog_ID = 'Your Page/Posts ID'; //specify id here
        $blog_post = get_post($blog_ID);
        $blog_slug = $blog_post->post_name;


        $url = $wp->request;
        if (strstr($url, $resource_slug) && strstr($url, $blog_slug)) {
            return true;
        } else {
            $post_slug = $post->post_name;
            $new_slug = home_url() . "/resources/blog/" . $post_slug;
            wp_redirect($new_slug);
        }
        exit;
    }
}
?>

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.