0

I'm sure this is a simple one but I'd like to get some insight on this. I have a vm running plex media server and I'm trying to setup mod_rewrite for this. I'd like to have an HTTP connection -> SSL -> Plex

Keeping it simple, without SSL the following works

ServerName plex

<Proxy *>
    Order deny,allow
    Allow from all
</Proxy>

ProxyRequests Off
ProxyPreserveHost On
RewriteCond %{HTTPS} !=on
ProxyPass / http://127.0.0.1:32400/
ProxyPassReverse / http://127.0.0.1:32400/

RewriteEngine on
RewriteCond %{REQUEST_URI} !^/web
RewriteCond %{HTTP:X-Plex-Device} ^$
RewriteRule ^/$ /web/$1 [R,L]

This allows me to enter

http://plex/

Which rewrites to

http://plex/web

And removes my port number, now if I take the same as above and use https at lines 9 and 10 I break the rewrite.

Interestingly, if I use

    <Proxy *>
        Order deny,allow
        Allow from all
    </Proxy>

    ProxyRequests Off
    ProxyPreserveHost On
    RewriteCond %{HTTPS} !=on
    ProxyPass / http://127.0.0.1:32400/
    ProxyPassReverse / http://127.0.0.1:32400/

    RewriteEngine on
    RewriteCond %{REQUEST_URI} !^/web
    RewriteCond %{HTTP:X-Plex-Device} ^$
    RewriteRule ^/?(.*) https://%{SERVER_NAME}:32400/web/$1 [R,L]

This works fine, but the port number is not removed. I understand this is because I'm including it in my rewrite rule.

So my question here is really two fold.

A) Why would using https instead of http at lines 9 and 10 not work as desired? B) What is the correct setup to forward http->https while using a rewrite rule?

tyia

user316114
  • 613
  • 5
  • 16
  • 1
    Possible duplicate of [How to enable mod\_rewrite for Apache 2.2](http://stackoverflow.com/questions/869092/how-to-enable-mod-rewrite-for-apache-2-2) – diziaq Dec 26 '15 at 08:40

1 Answers1

0

Try %{HTTP_HOST} instead of %{SERVER_NAME}

covener
  • 16,079
  • 2
  • 27
  • 40