CPTUI rewrite disable when no post in CPTUI has been found

I am guessing that you are searching for post and if post not found then you want to display page.

If you are using WordPress default search then you can try this code

function my_cptui_add_post_type_to_search( $query ) {

if ( is_admin() || ! $query->is_main_query() ) {
    return;
}

if ( $query->is_search() ) {
    $query->set(
        'post_type',
        array( 'post', 'page' )
    );
  }

}

add_filter( 'pre_get_posts', 'my_cptui_add_post_type_to_search' );