Apache/htaccess to HTTPS if SSL is cert is installed

ShinJii

Verified User
Joined
Mar 20, 2014
Messages
219
Apache/htaccess to HTTPS if SSL cert is installed

Hi,
I have a platform for example with different domains/subdomains and when I update my script for all domains/subdomains it updates all files with changes... so when I update for example .htaccess it changes everywhere and I need something like this:

Domain X hasn't SSL installed, Domain Y has, so how to change htaccess or httpd conf to know if Domain Y has SSL installed and redirect all traffic to https? But Domain X hasn't and redirect all to http? Is this possible? I think it's not possible in htaccess but maybe in httpd conf?
Code:
RewriteCond %{HTTPS} !=on
etc. is not working because it just know if USER uses HTTPS or HTTP, not this domain...

How to figure it out?... please help :)
 
Last edited:
Hello,

Depending on your permissions on the server you can either use API or control results from file:

grep ssl=ON /usr/local/directadmin/data/users/username/domains/domain.com.conf

regular users can not read domain's config, you need to be root.
 
let's assume that I can do that, so how to connect it with httpd.conf or .htaccess?
 
Depending on ssl=ON you can either overwrite/copy .htaccess from a template with SSL enabled/disabled, or touch a file/remove, and then check existence of the file with mod_rewrite on per domain bases.

RewriteCond %{HTTPS} !=on
RewriteCond /home/username/domains/domain.com/ssl_on -f

Something like this...
 
Back
Top