PHP Script to perform Reverse Proxy Functionality
A simple PHP script that can be used as a ReverseProxy. Although you can use Nginx, mod_proxy or a dedicated software like Squid for this purpose, there are instances that you favor the ability to just do it in a PHP script that can be dropped in a single folder. There could be various reasons:, (*1)
Use composer to install it, (*2)
composer create-project buonzz/reverseproxy
edit config.php, (*3)
define('MASKED_DOMAIN', 'http://www.google.com'); define('PROXY_SUBFOLDER', 'reverseproxy'); define('FOLLOW_LOCATION', FALSE);
edit .htaccess, (*4)
RewriteEngine on RewriteCond $1 !^(index\.php) RewriteRule ^(.*)$ /reverseproxy/index.php/$1 [L]
This directives allows the reverseproxy to catch all the URI intented for the original domain, like for example, (*5)
http://www.originaldomain.com/blog/102014/hello-world
With this setting, you can use, (*6)
http://www.yourdomain.com/reverseproxy/blog/102014/hello-world
and the uri will be passed to the index.php and can then be passed to the original domain to rerieve the contents. Remember that if you are serving the contents from the root domain you only need to use this, (*7)
RewriteEngine on RewriteCond $1 !^(index\.php) RewriteRule ^(.*)$ /index.php/$1 [L]