How to setup ssl using only .htaccess file

12,539

You can redirect from plain HTTP to HTTPS, but you cannot activate SSL/TLS from htaccess.

To activate SSL/TLS, you must use SSLEngine among other directives

SSLEngine on

As you can see from the documentation,

Context: server config, virtual host

this is only possible in server config or virtual host context, but not in directory and .htaccess context.

This means, you must go through the means your web hosting provider gives you. Probably, activating alone is less expensive or even free of charge, when you already have certificates. Usually, certificates are the expensive part in using HTTPS. Activating SSL in contrast is a one time configuration.

Share:
12,539
Raaghu
Author by

Raaghu

Website design enthusiastic , have experience in Photoshop, Dreamweaver, HTML , CSS, Javascript , PHP, JAVA .... supporter of Equality and Freedom for everyone

Updated on August 26, 2022

Comments

  • Raaghu
    Raaghu over 1 year

    Has anyone tried to setup ssl for a website using only .htaccess file?

    I read through many documents which points to apache's httpd.conf file, to add some lines inside <virtual-host> tag.
    But I don't have access to httpd.conf file on my web hosting ...
    I can only put . htaccess file in my hosting directory.
    So is there a way to achieve HTTPS website using only the .htaccess file.

    NOTE: I already have certificates for my domain.