/foo?x=1 if ($upstreamPath === '') $upstreamPath = '/'; $url = rtrim($API_BASE_URL, '/') . $upstreamPath; // ヘッダそのまま(最低限) $headers = []; foreach (getallheaders() as $k => $v) { if (strtolower($k) === 'host') continue; $headers[] = "$k: $v"; } $context = stream_context_create([ 'http' => [ 'method' => $method, 'header' => implode("\r\n", $headers), 'content' => in_array($method, ['POST', 'PUT', 'PATCH']) ? file_get_contents('php://input') : null, 'ignore_errors' => true, // 4xx/5xxも受け取る ] ]); $response = file_get_contents($url, false, $context); // ステータスコードをそのまま返す if (isset($http_response_header[0])) { preg_match('#HTTP/\d\.\d\s+(\d+)#', $http_response_header[0], $m); if (!empty($m[1])) { http_response_code((int)$m[1]); } } // ヘッダも最低限返す foreach ($http_response_header as $h) { if (stripos($h, 'Transfer-Encoding:') === 0) continue; if (stripos($h, 'Connection:') === 0) continue; header($h, false); } echo $response; exit; } // ===== それ以外は静的(例: dist/index.html) ===== readfile(__DIR__ . '/dist/index.html');