WordPress rewrite does not work for some reason

I am new to WordPress rewrites, so after some StackExchange reading i have figured it out. All rewrites should be passed to index.php, then i can call the page that i want to redirect to, like this:

function custom_rewrite_basic() {
    add_rewrite_rule( 'validate_data.php', 'index.php?pagename=validate-data', 'top' );
}
add_action( 'init', 'custom_rewrite_basic' );

In addition i wanted to pass some POST data from the old page to the new page, so i did it like this:

function custom_rewrite_basic() {
    add_rewrite_rule( '^validate_data.php(.+)/?$', 'index.php?pagename=validate-data', 'top' );
}
add_action( 'init', 'custom_rewrite_basic' );

Hope that helps new starters like me some day 🙂