user558134
user558134

Reputation: 1129

Check if apache has a ssl certificate installed with htaccess

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!

Upvotes: 2

Views: 3423

Answers (2)

user207421
user207421

Reputation: 311050

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

Upvotes: 0

poncha
poncha

Reputation: 7866

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>

Upvotes: 2

Related Questions