I seem to be having trouble with Apache's mod_rewrite to rewrite URL requests while using it with mod_proxy to act as a reverse proxy. In summary, I'm trying to redirect requests to unminified CSS to my minified CSS located in another directory.
I currently have a web app requesting it's CSS at https://example.com/assets/css/styles.css
. I have my minified CSS stored at https://example.com/assets/css/min/styles.min.css
. Because I can not change the code where the CSS is linked, I want to use Apache's mod_rewrite to turn all requests for assets/css/styles.css
to assets/css/min/styles.min.css
.
Also, the web app is currently running on a separate backend server, 192.168.1.100
, so I have ProxyPass and ProxyPassReverse set up as
ProxyPass / http://192.168.1.100/
ProxyPassReverse / http://192.168.1.100/
Currently, I've tried adding
<Location /assets/css>
RewriteEngine On
RewriteBase /assets/css
RewriteCond %{REQUEST_URI} ^/assets/css/((.+)\.css)$
RewriteCond %{DOCUMENT_ROOT}/assets/css/min/%2.min.css -f
RewriteRule ^(.+)$ min/%2.min.css [L]
</Location>
I've also tried adding a trailing slash at the end of /assets/css
but that didn't do anything. I'm currently at a loss, as I'm not the best at mod_rewrite.
I think it is likely due to the interactions between Mod_Proxy and Mod_Rewrite that is causing the issue. I've taken the Location block snippet from another one of my projects and adapted the file paths appropriately. It was working correctly on that project, which was not using Mod_Proxy and was serving the content directly.