Fixing link rel=”next” in Yoast SEO for paginated links

In the current version of Yoast, this link is rendered by presenters/rel-next-presenter.php, which contains this filter:

    public function present() {
        $output = parent::present();
    
        if ( ! empty( $output ) ) {
          /**
           * Filter: 'wpseo_next_rel_link' - Allow changing link rel output by Yoast SEO.
           *
           * @api string $unsigned The full `<link` element.
           */
          return \apply_filters( 'wpseo_next_rel_link', $output );
        }
    
        return '';
    }

So, I’d suggest correcting this by implementing a filter in e.g. your functions.php, such as:

    add_filter( 'wpseo_next_rel_link', 'custom_change_wpseo_next' );

    function custom_change_wpseo_next( $oldLink ) {

        $new_link = 'https://example.com/index.php/page/2';
        $link = '<link rel="next" href="'. $new_link .'" />' . PHP_EOL;
        
        return $link;

    }

Does that do it?