request instanceof Http || $result === '' || $result === null) { return $result; } $effectiveType = $type ?? UrlInterface::URL_TYPE_LINK; if (!\in_array($effectiveType, [ UrlInterface::URL_TYPE_LINK, UrlInterface::URL_TYPE_DIRECT_LINK, UrlInterface::URL_TYPE_WEB, ], true)) { return $result; } if ($this->tunnelRequestDetector->getTunnelStoreCode($this->request) === null) { return $result; } $parts = parse_url($result); if ($parts === false || empty($parts['host'])) { return $result; } $requestHost = $this->request->getHttpHost(); if ($requestHost === '' || strcasecmp((string) $parts['host'], $requestHost) === 0) { return $result; } $scheme = $this->request->isSecure() ? 'https' : 'http'; $path = $this->pathForTunnelRewrite($scheme, $parts['path'] ?? '/', (string) $subject->getCode()); $query = isset($parts['query']) ? '?' . $parts['query'] : ''; $fragment = isset($parts['fragment']) ? '#' . $parts['fragment'] : ''; return $scheme . '://' . $requestHost . $path . $query . $fragment; } /** * Prefer path from persisted tunnel base URL (matches holesail vhost) when production base path differs. */ private function pathForTunnelRewrite(string $scheme, string $fallbackPath, string $storeCode): string { $state = $this->tunnelRegistry->getByStoreCode($storeCode); if ($state === null) { return $fallbackPath; } $preferSecure = $scheme === 'https'; $ref = $preferSecure ? $state['secure_base_url'] : $state['unsecure_base_url']; if (trim((string) $ref) === '') { $ref = $preferSecure ? $state['unsecure_base_url'] : $state['secure_base_url']; } if (trim((string) $ref) === '') { return $fallbackPath; } $parsed = parse_url((string) $ref); if ($parsed === false) { return $fallbackPath; } $path = $parsed['path'] ?? ''; if ($path === '' || $path === null) { return '/'; } return $path; } }