i try redirect all requests from non localhost connection from http to https.
i use this combination https-> nginx -> varnish -> apache2 and want redirect direct connections to apache without ssl
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_HOST} !=localhost
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} ^(?:www\.)?(.*)$ [NC]
RewriteRule (.*) https://%1%{REQUEST_URI} [L,R=301]
this not work
Update 1
i put this:
RewriteCond %{REMOTE_ADDR} !=localhost
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} ^(?:www\.)?(.*)$ [NC]
RewriteRule (.*) https://%1%{REQUEST_URI} [L,R=301]
and this is work - url in browser is redirected to https:// but i have unlimited loops, so apache redirect to https:// nginx as apache for http and it redirect. How to fix it?
UPDATE 2
if i change line
RewriteCond %{REMOTE_ADDR} !=localhost
to
RewriteCond %{REMOTE_ADDR} !=127.0.0.1
redirection stop work
UPDATE 3 This not work because i have
http -> varnish -> apache or https -> nginx -> varnish -> apache
so for apache all time have 127.0.0.1 so i need know this is varnish request direct from http or from varnish
maybe add in nginx some var (header ?) and if request don't have this header in apache htacces redirect to https. What is best way to do this ?
UPDATE 4 i setup i nginx -
add_header Mea-request nginx;
and
in apache
RewriteCond %{HTTP:Mea-request} != ^nginx$
RewriteCond %{HTTP_HOST} ^(?:www\.)?(.*)$ [NC]
RewriteRule (.*) https://%1%{REQUEST_URI} [L,R=301]
but still this not work
i think this line is not correct
RewriteCond %{HTTP:Mea-request} != ^nginx$