'text/css', 'js' => 'application/javascript', 'json' => 'application/json', 'png' => 'image/png', 'jpg' => 'image/jpeg', 'jpeg' => 'image/jpeg', 'gif' => 'image/gif', 'svg' => 'image/svg+xml', 'ico' => 'image/x-icon', 'woff' => 'font/woff', 'woff2' => 'font/woff2', 'ttf' => 'font/ttf', 'eot' => 'application/vnd.ms-fontobject', 'txt' => 'text/plain', 'xml' => 'application/xml' ]; $extension = strtolower(pathinfo($requestedFile, PATHINFO_EXTENSION)); if (isset($mimeTypes[$extension])) { header('Content-Type: ' . $mimeTypes[$extension] . '; charset=utf-8'); } readfile($requestedFile); exit; } // Requisição para página web - rotear para frontend // Remover o nome do diretório do projeto do path se existir $baseDir = basename(__DIR__); $cleanPath = $requestPath; // Se o path começa com o nome do diretório do projeto, removê-lo // IMPORTANTE: Verificar o caso com / depois PRIMEIRO para evitar remover parcialmente if (strpos($requestPath, '/' . $baseDir . '/') === 0) { // Exemplo: /gestao-veiculos/dashboard.html -> /dashboard.html $cleanPath = substr($requestPath, strlen('/' . $baseDir)); } elseif ($requestPath === '/' . $baseDir) { // Exemplo: /gestao-veiculos -> / $cleanPath = '/'; } // Garantir que começa com / if ($cleanPath === '' || $cleanPath[0] !== '/') { $cleanPath = '/' . $cleanPath; } $frontendPath = __DIR__ . '/frontend' . $cleanPath; // --- Nova Lógica de Roteamento Frontend --- // 1. Se o arquivo existe no frontend (ex: /login.php -> frontend/login.php) if (file_exists($frontendPath) && is_file($frontendPath)) { $extension = strtolower(pathinfo($frontendPath, PATHINFO_EXTENSION)); // PHP: Executar (require) preservando execução local if ($extension === 'php') { chdir(dirname($frontendPath)); // Mudar CWD para frontend para includes funcionarem require $frontendPath; exit; } // Estáticos: Servir arquivos conhecidos $mimeTypes = [ 'html' => 'text/html', 'css' => 'text/css', 'js' => 'application/javascript', 'json' => 'application/json', 'png' => 'image/png', 'jpg' => 'image/jpeg', 'jpeg' => 'image/jpeg', 'gif' => 'image/gif', 'svg' => 'image/svg+xml', 'ico' => 'image/x-icon', 'woff' => 'font/woff', 'woff2' => 'font/woff2', 'ttf' => 'font/ttf', 'eot' => 'application/vnd.ms-fontobject' ]; if (isset($mimeTypes[$extension])) { header('Content-Type: ' . $mimeTypes[$extension] . '; charset=utf-8'); readfile($frontendPath); exit; } } // 2. Se não encontrou, testar se é uma URL sem extensão (ex: /dashboard -> /dashboard.php ou .html) // Prioridade: .php > .html $candidatesExt = ['.php', '.html']; if (!empty($cleanPath) && $cleanPath !== '/') { foreach ($candidatesExt as $ext) { $tryPath = __DIR__ . '/frontend' . $cleanPath . $ext; if (file_exists($tryPath)) { if ($ext === '.php') { chdir(dirname($tryPath)); require $tryPath; exit; } else { header('Content-Type: text/html; charset=utf-8'); readfile($tryPath); exit; } } } } // 3. Homepage / Raiz $isRootPath = ($cleanPath === '' || $cleanPath === '/' || $requestPath === '' || $requestPath === '/' || $requestPath === '/' . $baseDir || $requestPath === '/' . $baseDir . '/'); if ($isRootPath) { // Ordem de prioridade para Homepage $indexFiles = [ 'index.php', 'login.php', 'index-new.html', 'index.html', 'dashboard.php' ]; foreach ($indexFiles as $file) { $path = __DIR__ . '/frontend/' . $file; if (file_exists($path)) { $ext = pathinfo($path, PATHINFO_EXTENSION); if ($ext === 'php') { chdir(dirname($path)); require $path; exit; } else { header('Content-Type: text/html; charset=utf-8'); readfile($path); exit; } } } } // Se chegou aqui, arquivo não encontrado - 404 http_response_code(404); header('Content-Type: text/html; charset=utf-8'); ?> Página Não Encontrada - ERP Veículos

404

Página não encontrada

Voltar para o início