2
votes

Is there a away to check if apache has a ssl certificate installed with htaccess, before running any RewriteCond or RewriteRule for https?

E.g.:

Apache has ssl certificate installed then RewriteCond {HTTPS} !on RewriteRule %{HTTP_HOST}%{REQUEST_URI}

Thanks!

2

2 Answers

2
votes

Instead of checking "if SSL certificate exists", check "if ssl module is on" - the latter requires a certificate by itself

<IfModule mod_rewrite.c>
RewriteEngine on

  <IfModule mod_ssl.c>
  RewriteCond %{HTTPS} !=on
  RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R=301,L]
  </IfModule>

</IfModule>
0
votes

If Apache doesn't have a certificate installed, the protocol cannot possibly be HTTPS.