Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to setup ssl using only .htaccess file

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.

like image 537
Raaghu Avatar asked Jun 17 '16 19:06

Raaghu


People also ask

Can you install SSL manually on a website?

It is possible to install SSL certificates manually on your Web Hosting. You can also learn how to install an SSL certificate automatically. You may also want to read our documentation page on purchasing an SSL certificate for manual installation.


1 Answers

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.

like image 105
Olaf Dietsche Avatar answered Oct 22 '22 17:10

Olaf Dietsche