It’s not possible to use a regex for that as category is not in the original URL.
Instead you may be able to use the beta permalink migration feature: https://redirection.me/support/site-options/
Thanks John!
I try the beta permalink migration but nothing changed!
I gave this /%postname%/%post_id%/ on the field and then click save!
I clear the cache also not working on any URL still getting 404 error.
Did you clear your browser cache?
As it states in the guide, it is in beta and doesn’t support every permalink.
Found solution playing little with PHP.
Puting the following code to functions.php you get redirection from /%postname%/%post_id%/ to /%category%/%postname%/%post_id%/
add_action( 'parse_request', 'maybe_redirect_old_permalinks' );
function maybe_redirect_old_permalinks( $wp ) {
if ( preg_match( '#^([^/]+)/(\d+)$#', $wp->request, $matches ) ) {
list ( $path, $slug, $id ) = $matches;
// Redirect to the new permalink, if the slug and ID match.
if ( $slug === get_post_field( 'post_name', $id ) ) {
wp_redirect( get_permalink( $id ), 301 );
exit;
}
}
}