Custom rewrite rule for hierarchical custom post type

You’re pretty close. Your rewrite rule is using the wrong query var, pagename should be just name.

Here’s a version that works for me on a fresh 4.4.1 install and twentysixteen theme-

function bvt_product_init() {
    $args = array(
        'label'                 => __( 'Product', 'domain' ),
        'description'           => __( 'Company products', 'domain' ),
        'supports'              => array( 'title', 'editor', 'excerpt', 'thumbnail', 'revisions', 'page-attributes' ),
        'taxonomies'            => array( 'category', 'post_tag' ),
        'hierarchical'          => true,
        'public'                => true,
        'show_ui'               => true,
        'show_in_menu'          => true,
        'menu_position'         => 5,
        'show_in_admin_bar'     => true,
        'show_in_nav_menus'     => false,
        'can_export'            => true,
        'has_archive'           => true,
        'rewrite'               => array( 'slug' => 'product' ),
    );
    register_post_type( 'product', $args );

    add_rewrite_rule( 
        '^product/([^/]+)/?$',
        'index.php?post_type=product&name=$matches[1]',
        'top'
    );
}
add_action( 'init', 'bvt_product_init' );

function bvt_product_flatten_hierarchies( $post_link, $post ) {
    if ( 'product' != $post->post_type ) {
        return $post_link;
    }
    $uri = '';
    foreach ( $post->ancestors as $parent ) {
        $uri = get_post( $parent )->post_name . "https://wordpress.stackexchange.com/" . $uri;
    }
    return str_replace( $uri, '', $post_link );
}
add_filter( 'post_type_link', 'bvt_product_flatten_hierarchies', 10, 2 );

One potential issue to look out for- hierarchical post types let you create posts with the same slug that have different parents. This normally works because they are queried by their parent/child paths. Without having that parent/child relationship in the URL structure, you can create posts that can never be queried on the front end if the slug matches an existing post. Just something to keep in mind.