.htaccess proxy pass through

#1
Hello,

I am trying to use .htaccess to proxy a site through as a domain hosted on the litespeed server.

This doesn't work:
RewriteEngine on
RewriteRule (.*) http://www.google.ca/$1 [P]

But this does:
RewriteEngine on
RewriteRule (.*) http://www.google.ca/$1 [L]

The latter redirects directly to google.ca. If I put an external App of type web server and set it to the google IP, and leave the .htaccess as the top example, it does a redirect instead of a reverse proxy.

I beleive I asked about this a few months back, and was told the feature was being implemented? Can anyone confirm?

Thanks.
 

NiteWave

Administrator
#3
your example of google looks not good: it looks like google can detect this and refuse to be reverse proxy'ed.
Code:
RewriteEngine on
RewriteRule (.*) http://www.google.ca/$1 [P]
assume the name of your external App of web server is google_backend, the rewrite rule should be
Code:
RewriteEngine on
RewriteRule (.*) http://google_backend/$1 [P,QSA]
this can archive success partly:
for example, access http://yousite.com/abcd, it will access google.ca/abcd, and return a "404 Not Found" page from google.

However if you use your own site instead of google, should be successful.
 
#4
This topic is old but I noticed small but noticeable difference in LSWS [P] directive implementation (which in my opinion is buggy).

Litespeed WebServer treats [P] as ordinary request to web server defined in External App tab. X-Forwarded-* are begin added but "host" stays same as requested. I came into problem trying to proxy to another virtual host on the same instance of litespeed - it just generated infinite loop.

Code:
RewriteCond %{REQUEST_URI} \.(jpg|png|jpeg)$
RewriteRule (.*) http://example.com/$1 [QSA,P]
This rule will generate request (shown below) to web server name "example.com" when mod_proxy in the same situation calls hostname "example.com". As you can see it contains "Host: proxy_me_to_example.com" instead of "Host: example.com".
Code:
GET /logo.png HTTP/1.1
Host: proxy_me_to_example.com
Connection: keep-alive
Cache-Control: max-age=0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.95 Safari/537.36
Accept-Encoding: gzip
Accept-Language: en-US,en;q=0.8,pl;q=0.6
X-Forwarded-Host: proxy_me_to_example.com
X-Forwarded-For: 127.0.0.1
Is there any workaround for this?
 
#6
Thank you for your reply. Unfortunately replacing [QSA,P] with suggested [P,E=Proxy-Host:example.com] didn't changed anything.
I even moved rules to Rewrite tab (instead of using .htaccess) - nothings changed.

p.s. I use normal lsws, not the o-s edition.
 
Top