3

I am trying to connect website (which is share hosted) to a remote server, so that when I access http://example.com/test/ it will display the results from http://remote-example.com/ (which is a web app server)

The web hosting provider only allows me to modify the .htaccess file for configuration, they said mod_proxy is enabled and it can be configured with the .htaccess file.

They linked me Apache's Documentation, but I haven't been able to get it to work. The hosting provider is using Lightspeed as the web server.

Is someone able to give me an example of what the .htaccess file should look like?

Can a reverse proxy be configured by modifying the .htaccess file only?

DocRoot
  • 297
  • 1
  • 10
crbon
  • 41
  • 1
  • 6
  • @MrWhite I've tried using `ProxyPass /test http://remote-example.com` and `ProxyReverse /test http://remote-example.com` But it didn't make any difference. Maybe the `proxy_http` module is not enabled – crbon Feb 04 '18 at 22:00
  • See also https://stackoverflow.com/questions/16297233/how-to-rewrite-location-response-header-in-a-proxy-setup-with-apache – reinierpost Nov 11 '19 at 13:05

2 Answers2

1

After some discussion with the hosting provider and further research into the issue I've concluded it cannot be done, due to the host restrictions.

The apache documentation itself specifies that ProxyPass can only be used in the Context: server config, virtual host, directory

Here is a link to some useful information which might help others Can ProxyPass and ProxyPassReverse work in htaccess

crbon
  • 41
  • 1
  • 6
  • Did you try using mod_rewrite's `RewriteRule` with the `P` flag? This allows mod_rewrite to route requests through mod_proxy and is the only way you'd be able to do this in a shared environment, without access to the server - which appears to be what your host is suggesting. (Then again, this still might not be sufficient. Then again, if it's not then why has your host enabled mod_proxy in the first place?) – DocRoot Feb 05 '18 at 11:19
  • 1
    @DocRoot they have rewrite and mod_proxy enabled but its still cannot be done under their current system – crbon Feb 05 '18 at 11:25
  • `RewriteRule [P]` corresponds to `ProxyPass`, but it doesn't implement `ProxyPassReverse`. I'm not sure it is possible to implement its behavior in `.htaccess` - you need to rewrite the `Location` response header. – reinierpost Nov 11 '19 at 11:30
0

It can be done, as long as you have the ability to rewrite the HTML that comes back from the origin server. I've been able to create a working reverse proxy for WordPress hosted on a shared server where I don't have access to the Apache configuration.

See: My comments in response to a similar question on Stack Overflow

Note: Proxied pages are noticeably slower.