URLs match but still coming back false

On the homepage, I’m trying to match the url in the browser with site url and I can’t use $page->isHomePage

$currentUrl = parse_url((isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? "https" : "http") . "://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]");
$siteUrl = parse_url($site->url()); ?>

but no matter what, when I compare the two, it still comes back false despite being the exact same url and both being a string.

 if($currentUrl  == $siteUrl): ?>
    true
    <?php else: ?>
    false
    <?php endif ?>

What am I missing?

Seems that it’s off by one backslash so I needed to do the following to the variable:

$siteUrl = $site->url().'/';

but that feels haphzard. Is there another way?

Either trim the slash from the end:

trim("://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]", '/')

(and maybe even for both URL just in case)

Or enforce trailing slashes.

Trimming seems easier. Just did this! Thank you :slight_smile: