custom wordpress rewrite

WordPress has two kinds of rewrite rules- internal and external. Internal rules are parsed by WordPress and routed to index.php. External rewrites get written to .htaccess and are not directed to WordPress.

Right now your rule is a mix between internal and external- you have it structured as an internal rule, but you have it incorrectly pointed to a file other than index.php.

If you want to use the WordPress environment within the code that receives this rewrite rule, it should be an internal rewrite. If you want this to be an external rule that is not processed by WordPress, then you need to change your rule to use $1 instead of $matches[1].

EDIT

here are a couple of methods, the first is the quick and dirty method –

Method One

Step 1 for both methods is to add a query var lpid to WordPress array of recognized query vars:

function wpa55759_query_vars( $query_vars ){
    $query_vars[] = 'lpid';
    return $query_vars;
}
add_filter( 'query_vars', 'wpa55759_query_vars' );

Step 2, add the rewrite rule to only set lpid when our rule is matched:

function wpa55759_rewrites(){
    add_rewrite_rule(
        'lp/(\d+)/?$',
        'index.php?lpid=$matches[1]',
        'top'
    );
}
add_action( 'init', 'wpa55759_rewrites' );  

Step 3, hook parse_request and check if our query var is set. If so, load lp.php from the template directory, and exit:

function wpa55759_parse_request( $request ){
    if( isset( $request->query_vars['lpid'] ) ):
        include( get_template_directory() . "/lp.php" );
        exit();
    endif;
    return $request;
}
add_action( 'parse_request', 'wpa55759_parse_request' );

To get the value of lpid inside lp.php:

global $wp;
echo $wp->query_vars['lpid'];

Basically we’re checking for our query var and cutting out early. WordPress never runs a database query to load posts or pages. Not sure what side effects this may have otherwise.

Method Two

The second method is to create a page within WordPress, lp, and point our rule at that, also passing the query var:

function wpa55759_rewrites(){
    add_rewrite_rule(
        'lp/(\d+)/?$',
        'index.php?pagename=lp&lpid=$matches[1]',
        'top'
    );
}
add_action( 'init', 'wpa55759_rewrites' );

Now you can create a template page-lp.php and access lpid with:

echo get_query_var( 'lpid' );

One additional option with this second method is to filter template_redirect and shortcut the template hierarchy, loading your own custom file:

function wpa55759_template_redirect(){
    global $wp_query;
    if( $wp_query->get( 'lpid' ) ):
        include( get_template_directory() . "/lp.php" );
        exit();
    endif;
}
add_filter( 'template_redirect', 'wpa55759_template_redirect' );