Configuring reverse proxy with mod_proxy rules using only .htaccess file

7,590

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

Share:
7,590

Related videos on Youtube

crbon
Author by

crbon

keeping it private.

Updated on September 18, 2022

Comments

  • crbon
    crbon over 1 year

    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?

    • crbon
      crbon over 6 years
      @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
    • reinierpost
      reinierpost over 4 years
  • DocRoot
    DocRoot over 6 years
    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?)
  • crbon
    crbon over 6 years
    @DocRoot they have rewrite and mod_proxy enabled but its still cannot be done under their current system
  • reinierpost
    reinierpost over 4 years
    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.