h5bp/server-configs-apache

%{HTTPS} optional and works only with mod_ssl enabled

Closed this issue · 2 comments

We have https site on virtual hosting with nginx (as front, we haven't access to configure it) + apache (only .htaccess rewrites for url) + php-fpm

nginx provide ssl config for users and hoster disabled redundant httpd mod_ssl and we don't have optional var %{HTTPS}

We need add checking for mod_ssl enabled and add fallback based on server port var.
For example

# Set %{ENV:PROTO} variable, to allow rewrites to redirect with the
# appropriate schema automatically (http or https).
RewriteCond %{SERVER_PORT} ^443$
RewriteRule ^ - [env=proto:https]

<IfModule mod_ssl.c>
  RewriteCond %{HTTPS} =on
  RewriteRule ^ - [env=proto:https]
  RewriteCond %{HTTPS} !=on
  RewriteRule ^ - [env=proto:http]
</IfModule>

# Redirect from the `http://` to the `https://` version of the URL.
# https://wiki.apache.org/httpd/RewriteHTTPToHTTPS
  RewriteCond %{ENV:PROTO} !=https
  RewriteCond %{REQUEST_FILENAME} !robots.txt$ [NC]
  RewriteCond %{REQUEST_FILENAME} !sitemap(.*).xml$ [NC]
  RewriteRule ^(.*)$ https://%{SERVER_NAME}/$1 [R=301,L]

Thanks for this report!
That said your case seems very specific (and weird, nginx+apache what? 😆).
Your change proposal adds a lot of complexity and a link to the port 443 which is not general enough IMHO.

we don't have optional var %{HTTPS}

Do you get any output/error from Apache?

Closing for inactive, but please re-open if it still occurs.