Cannot make custom search permalink to work in a fully custom theme. Search string $_GET[‘s’] is always empty

I figured it out. The error was in my code in search.php template file.

My previous code was this:

if( empty( $_GET['s'] ) ) {
    echo 'No search';
    exit;
}

$s = $_GET['s'];
echo $s;

while it should be this:

if( empty( get_query_var( 's' ) ) ) {
    echo 'No search';
    exit;
}

$s = get_query_var( 's' );
echo $s;

Since there is no literal query string in the URL anymore and it has been redirected to a new URL with a different pattern where I won’t be able to grab the value using $_GET['s']