1

I want to setup an apache 2.4 virtualhost to serve 'physical' files that exist in the directory 'var/www/html' (like robots.txt for example).

If the requested URI is not an existing file, the reverse proxy rules should be used.

I read about conditional ProxyPassing like so

<If "! -f %{REQUEST_FILENAME}">
    #ProxyPassReverseCookiePath / /author
    ProxyPassReverseCookieDomain localhost mywebsite.com

    #ProxyPass           / ajp://localhost:7009/
    #ProxyPassReverse    / ajp://localhost:7009/
    ProxyPass           / http://localhost:7080/
    ProxyPassReverse    / http://localhost:7080/
</If>

and after those lines I'd put my location directives.

But it does not work, instead it's saying AH00526: Syntax error on line 45 of /etc/apache2/sites-enabled/000-default.conf: ProxyPass cannot occur within <If> section

I read about this here: https://serverfault.com/a/655873/149187 (not the accepted answer, but 3 upvotes).

How can I use the if-tag? Or is there a better way to achieve what I'm looking for? Thanks for pointing me in the right direction!

Manticore
  • 109
  • 3

1 Answers1

0

Something like that (not tested):

RewriteEngine on
RewriteCond "/var/www/html/%{REQUEST_URI}" !-f
RewriteRule "^/(.*)$" "http://localhost:7080/$1" [P]
Patrick Mevzek
  • 9,921
  • 7
  • 32
  • 43