Site icon Hip-Hop Website Design and Development

Adding the amp url prefix to the beginning

I created my own AMP template with this and the URL prefix became ‘amp’

<?php
define( 'AMP_QUERY_VAR', apply_filters( 'amp_query_var', 'amp' ) );
add_rewrite_endpoint( AMP_QUERY_VAR, EP_PERMALINK );
add_filter( 'template_include', 'amp_page_template', 99 );
function amp_page_template( $template ) {
    if( get_query_var( AMP_QUERY_VAR, false ) !== false ) {
        if ( is_single() ) {
            $template = get_template_directory() .  '/amp-single.php';
        } 
    }
    return $template;
}

URL structure with this:

`www.example.com/post-name/amp/`

and I want the URL to be like this:

`www.example.com/amp/post-name/`

How can i do this in this code?