<?php

require($_SERVER["DOCUMENT_ROOT"] . "/bitrix/modules/main/include/prolog_before.php");

header('Content-Type: application/xml; charset=utf-8');

global $APPLICATION;
$APPLICATION->RestartBuffer();
$requestXmlFile = $APPLICATION->GetCurPage();
$requestXmlFile = preg_replace('/[^a-zA-Z0-9\.-]/', '', $requestXmlFile);
$requestXmlFile = preg_replace('/\.+/', '.', $requestXmlFile);
$filePath = $_SERVER['DOCUMENT_ROOT'] . '/' . $requestXmlFile;

if (file_exists($filePath)) {
    $sitemap = file_get_contents($filePath);
    $domain = SITE_SERVER_NAME;
    if (($arCity = MG\HP\Site\Services\GeoLocationService::getCity()) && $arCity["domain"]) {
        if ($domain !== $arCity["domain"]) {
            $sitemap = str_replace(['//spb.rostcom.com', '//'.$domain], '//'.$arCity["domain"], $sitemap);
        }
    }
    echo $sitemap;
} else {
    if (!defined("ERROR_404")) {
        define("ERROR_404", "Y");
    }
    \CHTTP::setStatus("404 Not Found");
}
exit;
?>