I have two Apache servers behind a load balancer. Both servers are identical and they are used as hosts for several customer's websites. They asked me to enable https access for all websites, together with unconditional redirect of http requests to https (so when someone selects http link returned by search engine, bookmark, etc gets https version of it).
Since there are multiple domains, I needed a multi-domain SSL certificate. I knew that there could be problems with SNI on older browsers, so I decided to instal the certificate on load balancer and let it does the termination. Given that SSL termination is performed on load balancer all traffic between load balancer and servers is unencrypted.
So, for both http and https traffic to any website, for example www.example.com, I have just one Virtual Host, because all traffic go via port 80:
<VirtualHost *:80>
DocumentRoot "/var/www/html/website001"
ServerName www.example.com
</VirtualHost>
Content of www.example.com website is physically located in /var/www/html/website001 folder:
Folder1
Folder2
file1.html
file2.html
index.html
.htaccess
...
Content of /var/www/html/website001/.htaccess is:
RewriteEngine on
#First block of rules
RequestHeader set X-Forwarded-Proto "http"
RewriteCond %{HTTP_HOST} ^www\.example\.com [NC]
RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R,L]
#Second block of rules
RewriteRule ^First-file$ /file1.html
RewriteRule ^Second-file$ /file2.html
First block of rules should do the unconditional redirect from http to https for every page, while second block should provide user friendly URLs for file1.html and file2.html. Hence, request for
http://www.example.com/First-file
should be rewriten to
https://www.example.com/First-file
and file1.html should be opened in browser. Unfortunately, second block of rules work only partially: it opens file1.html, but it doesn't rewrite the url which is displayed as
https://www.example.com/file1.html
When first block of rules is removed or commented out, the second block of rules works properly.
Does anyone have any idea how this can be solved?