
Я пытался отредактировать код следующим образом, перенаправление работает, но страница не загружается, есть ошибка «ERR_TOO_MANY_REDIRECTS»
(Я также пытался перенаправить с помощью плагина regex Yoast и перенаправления плагин, но все равно та же ошибка.)

// Redirection from old slug to new slug
add_action('template_redirect', 'redirect_old_blog_urls');
function redirect_old_blog_urls()
{
if (is_singular('blog')) {
global $post;
// Get the current URL
$current_url = home_url(add_query_arg(array(), $wp->request));
// Define the old URL pattern
$old_url = home_url('blogs/' . get_the_category($post->ID)[0]->slug . '/' . $post->post_name);
// Define the new URL pattern
$new_url = home_url('news-and-insights/' . $post->post_name);
// Check if the current URL matches the old URL pattern
if (untrailingslashit($current_url) === untrailingslashit($old_url)) {
wp_redirect($new_url, 301);
exit;
}
}
}
Подробнее здесь: https://stackoverflow.com/questions/788 ... -permalink
Мобильная версия