<?php
$uri = $_SERVER['REQUEST_URI'];
$path = parse_url($uri, PHP_URL_PATH);


$filename = ltrim($path, '/');


$realFile = $_SERVER['DOCUMENT_ROOT'] . '/' . $filename;

if (!file_exists($realFile)) {
    header("HTTP/1.0 404 Not Found");
    echo "Sitemap file not found";
    exit;
}


$content = file_get_contents($realFile);


$oldDomain = 'skatgroup.ru';
$currentHost = $_SERVER['HTTP_HOST'];

if ($currentHost !== $oldDomain && $currentHost !== 'www.' . $oldDomain) {

    $protocol = (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off' || $_SERVER['SERVER_PORT'] == 443) ? "https://" : "http://";
    $newDomainPrefix = $protocol . $currentHost;

    $content = str_replace('https://' . $oldDomain, $newDomainPrefix, $content);
    $content = str_replace('http://' . $oldDomain, $newDomainPrefix, $content);
    $content = str_replace('//' . $oldDomain, '//' . $currentHost, $content);
}

header('Content-Type: application/xml; charset=utf-8');
echo $content;
?>