<?php
// Prevent redirect loop: inspect HTTP_HOST directly for the port
$host = $_SERVER['HTTP_HOST'] ?? '';

// Check if port 444 is already attached to the Host header
if (!str_ends_with($host, ':444')) {
    $requestUri = $_SERVER['REQUEST_URI'] ?? '/shreesha_heights/';
    
    // Clean host by removing any existing standard port notation
    $cleanHost = preg_replace('/:\d+$/', '', $host);
    if (empty($cleanHost)) {
        $cleanHost = 'demo.sevasathi.online';
    }

    header('Location: https://' . $cleanHost . ':444' . $requestUri, true, 301);
    exit;
}

?>