I have an application that runs on https://ip:8443. I have an Apache2 proxy server that stands in front of this application with the following config.
<VirtualHost *:80>
ServerName mydomain
ServerAlias mydomain
Redirect permanent / https://mydomain/
</VirtualHost>
<VirtualHost *:443>
ProxyPreserveHost On
ProxyRequests Off
SSLProxyEngine On
ServerName mydomain
ServerAlias mydomain
ProxyPass / https://ip:8443/
ProxyPassReverse / https://ip:8443/
SSLCertificateFile /etc/letsencrypt/live/mydomain/cert.pem
SSLCertificateKeyFile /etc/letsencrypt/live/mydomain/privkey.pem
</VirtualHost>
Now when I hit https://mydomain on the browser it works fine and shows https://ip:8443 content.
Now I want when someone visits https://mydomain to be redirected to another URL https://mydomain/subfolder which shows https://ip:8443/subfolder.
I searched for a week and tried a lot of solutions here but they didn't work.
This solution worked for me.
I added the following lines to <VirtualHost *:443>
<VirtualHost *:443>
...
RewriteEngine On
RewriteCond %{REQUEST_URI} ^/$
RewriteRule (.*) https://mydomain/subfolder/ [R=301,L]
</VirtualHost>