<?php
// Este archivo recibe todas las peticiones a booking.wayfinderrestaurant.com
// y sirve los archivos de la carpeta correcta

// Obtener la URL solicitada
$request = $_SERVER['REQUEST_URI'];

// Si la petición es la raíz, servir index.php
if ($request == '/' || $request == '') {
    include '/home/wayfinder/public_html/booking.wayfinderrestaurant.com/index.php';
    exit;
}

// Limpiar la ruta (quitar / al inicio)
$file = ltrim($request, '/');

// Construir la ruta completa al archivo
$file_path = '/home/wayfinder/public_html/booking.wayfinderrestaurant.com/' . $file;

// Verificar si el archivo existe
if (file_exists($file_path)) {
    // Si es PHP, incluirlo
    if (pathinfo($file_path, PATHINFO_EXTENSION) == 'php') {
        include $file_path;
    } else {
        // Si es otro tipo de archivo, servirlo con el contenido adecuado
        $mime_types = [
            'html' => 'text/html',
            'css' => 'text/css',
            'js' => 'application/javascript',
            'png' => 'image/png',
            'jpg' => 'image/jpeg',
            'gif' => 'image/gif'
        ];
        $ext = pathinfo($file_path, PATHINFO_EXTENSION);
        if (isset($mime_types[$ext])) {
            header('Content-Type: ' . $mime_types[$ext]);
        }
        readfile($file_path);
    }
} else {
    // 404
    header("HTTP/1.0 404 Not Found");
    echo "Archivo no encontrado: " . htmlspecialchars($request);
}
?>

