Reputation: 1129
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
Reputation: 311050
If Apache doesn't have a certificate installed, the protocol cannot possibly be HTTPS.
Upvotes: 0
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