Changing post per page causing 404 for pagination. Need a redirect htaccess rule

i found a solution with no use of htaccess but using the WP function wp_redirect. copy and past on functions.php

function redirect_paginated_404() {
    if (is_404()) {

       $url = $_SERVER['REQUEST_URI']; //read the url
       $search="/page/"; //chose the word of the url

       if ( strpos( $url, $search ) !== false ) { //if i find the string /page/

       //search the string /page/ in the url and delete everything after it, so the incorrectly page number
          $short = substr($url, 0, strpos( $url, $search)); 

          wp_redirect( $short, '301' ); // redirection function with the first page of category
                     exit;
                }
            }
        }
         add_action('template_redirect', 'redirect_paginated_404');

actually i don’t know if could damage SEO or not, but the redirection is working fine. What do you think about it? is it better to leave the 404 error or i can use something like this?

source