Redirect to page 2 after comment

After reading a bit on regex and preg, starting from a previous example of a similar problem and testing it I was able to answer my own question.

I added this function to functions.php:

<?php
/** Plugin Name: WPSE (#167237) Redirect after comment */

add_filter('comment_post_redirect', 'redirect_after_comment');
function redirect_after_comment($location)
{
    return preg_replace("/comment-page-([\d]+)\/#comment-([\d]+)/", "2", $location);
}

It’s replacing the part of the url stating the comment page and comment anchor with “2”. It may not be the cleanest solution but it’s how I managed to do as a beginner.

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)