I've got a wordpress wordpress plugin that actually works fine from the url such as the following:

domain.com/wordpress/wp-content/plugins/my-plugin/file.php?segments=category/add

But, I have to obtain a rewrite rule inside to ensure that the above mentioned could be utilized through the cleaner url:

domain.com/wordpress/directory/category/add

For that existence of me I simply can't get this use the Wordpress Rewrite Class. While using example they've around the WP class reference page I attempted the next during my wordpress plugin file:

add_filter( 'rewrite_rules_array','my_insert_rewrite_rules' );
add_filter( 'query_vars','my_insert_query_vars' );
add_action( 'wp_loaded','my_flush_rules' );

// flush_rules() if our rules are not yet included
function my_flush_rules(){
    $rules = get_option( 'rewrite_rules' );

    if ( ! isset( $rules['(directory)/(.*)$'] ) ) {
        global $wp_rewrite;
        $wp_rewrite->flush_rules();
    }
}

// Adding a new rule
function my_insert_rewrite_rules( $rules )
{
    $newrules = array();
    $newrules['(directory)/(.*)$'] = 'wp-content/plugins/my-plugin/file.php?segments=$matches[2]';
    return $newrules + $rules;
}

// Adding the id var so that WP recognizes it
function my_insert_query_vars( $vars )
{
    array_push($vars, 'segments');
    return $vars;
}