How to configure a proxy server in .htaccess

The Apache documentation states that RewriteRule should be placed in the server configuration, but they can be placed in htaccess due to co-location situations. I am in such a situation.

I am trying to configure a transparent proxy:

RewriteEngine On RewriteCond %{REQUEST_URI} ^/foo [OR] RewriteCond %{REQUEST_URI} ^/bar RewriteRule ^(.*)$ http://example.com/$1 [P] 

This works fine ... except for redirection (for example, if /foo redirected to /bar ). Redirects return to example.com and not to my server.

I understand that the ProxyPassReverse directive ProxyPassReverse solve this, but I get the "Internal Server Error" page when I add it to .htaccess

Unlike Rewrite directives, ProxyPassReverse will not work in htaccess .

How to configure a transparent proxy server in a situation with shared hosting, or is it impossible?

(This seems reasonable, since Rewrite already gets 80% of the path, and having a transparent proxy in one htaccess will not prevent it from having it in another.)

+8
apache proxy .htaccess transparentproxy
source share
1 answer

Unfortunately, I'm pretty sure what you want to do is impossible: I'm trying to do the same! From my research, I am sure that this is not possible.

Simply put, you need to use ProxyPassReverse, which is only available at the VirtualHost level (or similar); not the htaccess level.

Edit: the only way I have achieved this is also to configure the server or the responder application to know it behind the proxy server and properly serve the pages. That is, I use .htaccess to redirect to another server as follows:

  RewriteEngine on RewriteRule (.*) http://localhost:8080/$1 [P,L] 

Then on the application server - in this case, installing JIRA - I configured Java Tomcat / Catalina to serve pages with proxied information:

  proxyName="my.public.address.com" proxyPort="80" 

However, this is not completely transparent; The application server must serve proxy pages. This may be helpful.

+12
source share

All Articles