Apache2 – Rewriting when using reverse proxy

apache-2.2mod-rewritereverse-proxy

Background

I want to set up utorrent with webui on my server.

Problem

Utorrent sets up its own webserver which, by default, listens on port 8080.

The ui is then accessed by accessing example.com:8080/gui

My goal is to have subdomain.server.com using reverse proxy.
The problem comes when I discovered that some urls are hard coded to /gui/* which of course breaks things.

I'm now trying to remove that initial /gui from the request using mod rewrite but for some reason it's not working.

I can access the site (I get the utorrent loading screen) but if I check my log I see that all requests to /gui/token.html get a 404 Not Found response, /token.html works just fine if I try it manually though.

I've tried moving the rewrite to the proxy but that doesn't work either.

What I have so far

Here is my virtual host file:

<IfModule mod_ssl.c>
<VirtualHost *:443>
    ServerName subdomain.example.com

    RewriteEngine  on
    RewriteRule ^/gui(/?)(.*)$ /$2

    ProxyRequests off
    ProxyPass / http://127.0.0.1:8080/gui/
    ProxyPassReverse / http://127.0.0.1:8080/gui/
    RequestHeader set Authorization "Basic YWRtaW46"
    ErrorLog /var/log/apache2/utorrent-error.log
    CustomLog /var/log/apache2/utorrent-access.log common

    SSLEngine on
    SSLCertificateFile /etc/ssl/certs/*.domain.crt
    SSLCertificateKeyFile /etc/ssl/private/*.domain.key
    SSLCACertificateFile /etc/ssl/certs/domain-ca-ssl.crt

    BrowserMatch "MSIE [2-6]" \
        nokeepalive ssl-unclean-shutdown \
        downgrade-1.0 force-response-1.0
    BrowserMatch "MSIE [17-9]" ssl-unclean-shutdown

</VirtualHost>

<proxy http://127.0.0.1:8080/gui/*>
    Order deny,allow
    Deny from all
    Allow from all
    AuthName subdomain.example.com
    AuthType Basic
    AuthUserFile /etc/utorrent/.htpasswd
    Require valid-user
</proxy>
</IfModule>

Best Answer

Turns out it was as simple as adding the [PT] flag to the rewrite