简体   繁体   中英

Internal redirect in Apache VirtualHost configuration

Accessing the Plex media server requires to access http://my-ip:32400/web which isn't very easy for non-techies to remember. I followed a blog post I found to simplify this:

<VirtualHost *:80>
    ServerName mediaserver

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

    ProxyRequests Off
    ProxyPreserveHost 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]
</VirtualHost>

I also pointed mediaserver on my DNS server to the correct IP. This works in a way. Now I can just type http://mediaserver to access the Plex media server. However, this redirects to http://mediaserver/web . In the RewriteRule there are R and L flags. I read the documentation for the flags, removed them and added PT flag. I also checked the documentation for internal redirecting, where I found the PT flag.

So, with the rewrite rule written as RewriteRule ^/$ /web/$1 [PT] , I thought it would internally redirect to /web/ and not show it in the URL. How do I fix this?

Try changing the rule to this:

RewriteRule ^/$ /web [L]
  • There is no group capture, so the $1 was not doing anything
  • The R is what causes the url to change in the browser. With just the L , you have an internal redirect, but the user doesn't see the rewritten url.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM