Based on this answer I created a function to change the shortlink from domain.tld?p=435 to domain.tld/435 and redirect domain.tld/435 to domain.tld/full-permalink:
function shorter_shortlink() {
global $post;
$shortURL = get_bloginfo('url').'/'.$post->ID;
if(!empty($shortURL)) {
return $shortURL;
} else {
return get_bloginfo('url').'/?p='.$post->ID;
}
}
add_filter('pre_get_shortlink', 'shorter_shortlink');
add_action( 'wp', function(){
global $wp;
if( is_numeric( $wp->request ) && empty( $wp->query_vars['page'] ) )
{
wp_redirect( get_permalink( absint( $wp->request ) ), 301 );
exit();
}
});
While testing it seems that this approach is not the best for the performance. I wonder if there´s a better solution for this matter?