Redirect all posts when change permalinks structure

#177280
Viewing 14 replies - 1 through 14 (of 14 total)
  • Anonymous
    Rank Math free

    Hello,

    Thanks for getting back to us and we regret the inconvenience due to the issue.

    You can use the following code to redirect all the previous posts link automatically redirect to the new structure. Please put the code in your theme’s functions.php file. Also, I hope you have updated the structure in your permalink settings – https://i.rankmath.com/v9LLH4

    add_action( 'template_redirect', function () {
    
    	global $wp;
    
    	$post_id = get_posts(
    		array(
    			'name'        => $wp->request,
    			'post_type'   => 'post',
    			'post_status' => 'publish',
    			'numberposts' => 1,
    			'fields'      => 'ids',
    		)
    	);
    	$post_id = reset( $post_id );
    
    	if ( $post_id && ! empty( $permalink = get_the_permalink( $post_id ) ) ) {
    		wp_safe_redirect( $permalink );
    		exit();
    	}
    } );

    If you require any further assistance don’t hesitate to get in touch. Thanks

    Redakcja
    Rank Math free

    You are amazing! Thanks a lot my friend. I wish you a good day and much success.

    Prabhat
    Rank Math agency

    Hello,

    We are super happy that we could address your concern. If you have any other questions in the future, know that we are here to help you.

    If you don’t mind us asking, could you please leave us a review (if you haven’t already) on https://wordpress.org/support/plugin/seo-by-rank-math/reviews/#new-post about your overall experience with Rank Math? We appreciate your time and patience.

    If you have another question in the future, please feel free to create a new forum topic, and it will be our pleasure to assist you again.

    Thank you.

    Redakcja
    Rank Math free

    It turned out that this code you submitted redirects homepage to the most recent entry. Everything else works, except this.

    I must add that I have multisite enabled and my server is NGINX.

    My home page is not the latest posts but a page built on Elementor.

    Hello,

    Thank you for the update.

    We might need to take a closer look at the settings. Please edit the first post on this ticket and include your WordPress & FTP logins in the designated Sensitive Data section.
    Sensitive Data Section

    It is completely secure and only our support staff has access to that section. If you want, you can use the below plugin to generate a temporary login URL to your website and share that with us instead:

    https://wordpress.org/plugins/temporary-login-without-password/

    You can use the above plugin in conjunction with the WP Security Audit Log to monitor what changes our staff might make on your website (if any):

    https://wordpress.org/plugins/wp-security-audit-log/

    Thank you, and we really look forward to helping you.

    Redakcja
    Rank Math free

    Hello,

    I have updated the sensitive data as requested. Can you please check further?

    Thank you.

    Redakcja
    Rank Math free

    Hi. Were you able to check it? I still don’t have a homepage. Your code is working fine, but it redirects my homepage to the most recent post.

    Redakcja
    Rank Math free

    Not only the home page is redirected to the newest post. Also the search engine is not working. Post preview as well. In a word, this code redirected everything …

    Redakcja
    Rank Math free

    I deleted the code you sent me. I couldn’t wait any longer. I am doing each post by hand now. It’s good that there are only 500 of them, not 50,000

    Anonymous
    Rank Math free

    Hello,

    Thanks for getting back to us and we regret the inconvenience due to the issue.

    Please let us know if you wish to process those 500 posts manually, or you want us to look further on this.


    We are looking forward to helping you. Thanks

    Redakcja
    Rank Math free

    I already did it manually.

    Prabhat
    Rank Math agency

    Hello,

    Thanks for your reply.

    Could you please confirm if the issue is sorted or is it still there?

    Also, if you have another question, please feel free to reach out, and it will be our pleasure to assist you again.

    Thank you.

    Redakcja
    Rank Math free

    Listen up. The problem is still there. I did 500 redirects manually and for me it is solved, but the problem still exists. It is worth adding information on how to set up regex redirection when changing permalinks.

    This way, other users won’t have a problem like me.

    Anonymous
    Rank Math free

    Hello,

    Thanks for getting back to us and we regret the inconvenience due to the issue.

    We will let the dev team know about it. 


    If you have another question, please feel free to create a new forum topic, and it will be our pleasure to assist you again.
    Thank you

    Hello,

    Since we did not hear back from you for 15 days, we are assuming that you found the solution. We are closing this support ticket.

    If you still need assistance or any other help, please feel free to open a new support ticket, and we will be more than happy to assist.

    Thank you.

Viewing 14 replies - 1 through 14 (of 14 total)

The ticket ‘Redirect all posts when change permalinks structure’ is closed to new replies.