Passing the JQuery string to Worldpress URL

The tutorial is outdated and it seems it missed to flush the rules.

function add_rewrite_rule_and_tag() {

    global $wp_rewrite;

    add_rewrite_rule( '^physician-profile/([^/]*)/?', 'physician-profile?lastName=$matches[1]', 'top' );
    add_rewrite_tag( '%lastName%','([^&]+)' );

    if ( ! isset( $wp_rewrite->rules['^physician-profile/([^/]*)/?'] ) )
        $wp_rewrite->flush_rules();

    return;

}

add_action( 'init', 'add_rewrite_rule_and_tag', 99 );

You can access the query var `lastName´ with

gloabl $wp_query;
$lastName = $wp_query->query_vars['lastName'];