THIS CODE LOOKS TO ADDRESS THE ASSET-LINKS LIKE .CSS, .JS, ETC. THIS VERSION OF THE CODE IS ABLE TO SUCESSFULLY CREATE 200s FOR .css, .html and .js BUT NOT ANY OTHER ASSETS LIKE .png, .jpg, etc. INDEX3.TXT WILL HAVE THE CODE WHICH MAKES ALL THE ASSET-LINKS 404s ]*>/i"; $rr = ''; $response = preg_replace($rs, $rr, $response); // Rewrite relative asset URLs in href/src attributes to this domain. $currentHost = $_SERVER['HTTP_HOST']; $response = preg_replace_callback( '/(\b(?:href|src)\s*=\s*["\'])([^"\']+)(["\'])/i', function ($matches) use ($currentHost, $proxiedUrl) { $url = $matches[2]; // Ignore fragments and non-web resources. if ( $url === '' || $url[0] === '#' || preg_match('/^(data:|javascript:|mailto:|tel:)/i', $url) ) { return $matches[0]; } // Already root-relative: keep it on the current domain. if ($url[0] === '/' && strpos($url, '//') !== 0) { return $matches[0]; } // Absolute URL. if (preg_match('/^https?:\/\//i', $url)) { $parsed = parse_url($url); if (empty($parsed['path'])) { return $matches[0]; } $newUrl = 'http://' . $currentHost . $parsed['path']; if (!empty($parsed['query'])) { $newUrl .= '?' . $parsed['query']; } return $matches[1] . $newUrl . $matches[3]; } // Resolve relative URLs against the original source URL. if ($proxiedUrl !== '') { $source = parse_url($proxiedUrl); if (!empty($source['scheme']) && !empty($source['host'])) { $basePath = isset($source['path']) ? $source['path'] : '/'; $baseDir = rtrim(str_replace('\\', '/', dirname($basePath)), '/'); $newPath = '/' . ltrim($baseDir . '/' . $url, '/'); return $matches[1] . 'http://' . $currentHost . $newPath . $matches[3]; } } return $matches[0]; }, $response ); echo $response; } ?>