- parse_url: documentation ( source)
- htmlspecialchars: documentation ( source)
<?php
$url = $_GET["u"];
if(parse_url($url, PHP_URL_HOST) === "example.com" ) {
echo "<script>window.location.href = '" . htmlspecialchars($url, ENT_QUOTES) . "';</script>";
} else {
echo "<script>window.location.href = 'https://example.com';</script>";
}