0

This may have a simple answer I'm not aware of, but I'm not familiar with redirects on Wordpress. Here's my question:

I had my default Posts routed to mysite.com/post-name.

I want to now route the default Posts to mysite.com/blog/post-name, which I was able to achieve through the Permalinks settings, using the custom structure /blog/%postname%/.

The problem now is that the old URLs (mysite.com/post-name) don't work (404). How do I redirect all of those old Posts to the new mysite.com/blog/post-name URL? There are a lot of posts, so I'm looking for a way to do this in bulk.

I've searched for answers, but haven't found anything satisfactory. Any help would be highly appreciated. Thanks.

2 Answers 2

0

There are lots of solutions to redirect from the old post URL to the new post URL.

  1. You can install a plugin "Safe Redirect Manager" and set it from the admin panel.
  2. You can write some snippet in the functions.php file as:
add_action('template_redirect', 'post_redirect_by_custom_filters');
function post_redirect_by_custom_filters() {
    global $post;
    // this array can contain category names, slugs or even IDs.
    $catArray = ['blog'];
    if (is_single($post->ID) && !has_category($catArray, $post)) {
        $new_url = "http://www.newurl.com/blog/{$post->post_name}/";  
        wp_redirect($new_url, 301);
        exit;
    }
}

For more details please follow the below link.

https://www.ryadel.com/en/wordpress-redirect-posts-categories-tags-custom-conditions-301-302/amp/

0

i have changed Custom URL Structure like example.com/post-name to example.com/%category%/%post-name% . there are a lot of pages around 1600 URL, Now I want to redirect my old URL to New URL, How can i do that with rankmath free version.

1
  • If you have a new question, please ask it by clicking the Ask Question button. Include a link to this question if it helps provide context. - From Review
    – cjbj
    Commented Oct 14, 2023 at 9:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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