url rewriting – File cannot get POST ID with rewrite rule enabled

I have this file that has always gotten the wordpress post_id correctly:

<?php
require('C:xampp/htdocs/wp-blog-header.php');
require('C:xampp/htdocs/wp-load.php');
?>

WP Post ID: <?php echo get_the_ID(); ?>

-Text test-

But now I have created a rewrite rule for that file, and the redirect works, but it doesn’t get the post_id, but it does show “-Text test-” that I added:

function custom_rewrite_basic() {
  add_rewrite_rule('^goto/((0-9)+)/?', 'wp-content/themes/default/template-parts/goto.php?p=$matches(1)', 'top');
}
add_action('init', 'custom_rewrite_basic');

function custom_rewrite_tag() {
  add_rewrite_tag('%goto%', '((^&)+)');
}
add_action('init', 'custom_rewrite_tag', 10, 0);

I appreciate any help you can give me.