diff --git a/.htaccess b/.htaccess new file mode 100644 index 0000000..1dfe98d --- /dev/null +++ b/.htaccess @@ -0,0 +1,5 @@ +RewriteEngine On +Options +FollowSymlinks +RewriteBase / +DirectoryIndex index.php +RewriteRule ^(.*)$ index.php [L] \ No newline at end of file diff --git a/index.php b/index.php new file mode 100644 index 0000000..208c810 --- /dev/null +++ b/index.php @@ -0,0 +1,36 @@ + + */ +$path = parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH); +$query = parse_url($_SERVER['REQUEST_URI'], PHP_URL_QUERY); + +$newPath = ltrim($path, '/'); +if ($query) { + $newPath .= '?' . $query; +} + +$base = 'https://it-stories.ru'; // сайт, на котором планируется бродить +$local = '//'.$_SERVER['SERVER_NAME']; +$proxyUrl = $base .'/'. $newPath; + +$contents = @file_get_contents($proxyUrl); + +$headers = $http_response_header; +$firstLine = $headers[0]; + +if ($contents === false) { + header("HTTP/1.1 503 Proxy error"); + die("Proxy error - failed to get content from $proxyUrl"); +} +$allowedHeaders = "!^(http/1.1|server:|content-type:|last-modified|access-control-allow-origin|Content-Length:|Accept-Ranges:|Date:|Via:|Connection:|X-|age|cache-control|vary)!i"; + +foreach ($headers as $header) { + if (preg_match($allowedHeaders, $header)) { + header($header); + } +} + +// подменяем ссылки для возможности хождения через прокси и выводим +echo str_replace($base, $local, $contents); \ No newline at end of file