1<?php 2 3// The url we're proxying to. 4$remoteUrl = 'http://example.org/'; 5 6// The url we're proxying from. Please note that this must be a relative url, 7// and basically acts as the base url. 8// 9// If your $remoteUrl doesn't end with a slash, this one probably shouldn't 10// either. 11$myBaseUrl = '/reverseproxy.php'; 12// $myBaseUrl = '/~evert/sabre/http/examples/reverseproxy.php/'; 13 14use Sabre\HTTP\Sapi; 15use Sabre\HTTP\Client; 16 17// Find the autoloader 18$paths = [ 19 __DIR__ . '/../vendor/autoload.php', 20 __DIR__ . '/../../../autoload.php', 21 __DIR__ . '/vendor/autoload.php', 22 23]; 24 25foreach ($paths as $path) { 26 if (file_exists($path)) { 27 include $path; 28 break; 29 } 30} 31 32 33$request = Sapi::getRequest(); 34$request->setBaseUrl($myBaseUrl); 35 36$subRequest = clone $request; 37 38// Removing the Host header. 39$subRequest->removeHeader('Host'); 40 41// Rewriting the url. 42$subRequest->setUrl($remoteUrl . $request->getPath()); 43 44$client = new Client(); 45 46// Sends the HTTP request to the server 47$response = $client->send($subRequest); 48 49// Sends the response back to the client that connected to the proxy. 50Sapi::sendResponse($response); 51