How to redirect http to https (port 80 to 443)
with Apache 2.2 on Debian Lenny
If you're about to configure a redirect of http to https, just like
I was required to on a Debian server. You'll probably wonder how to
achieve that just, just like I wondered today.
There are plenty of ways to solve the task, first thing that poped
up on my mind was to use PHP redirect, however I rethinked over it
and reconsidered that using php redirect is too heavy for the
server in terms of performance.
This way though it's quick and easily achievable would execute the
php code
header('Location: https://domain.com/index.html');
each time accessed, this on a loaded server will create a real
performance issues.
Therefore I considered on to achieve the task on Apache
level.
After a quick research on google I find the quick solution.
The whole solution comes to adding two lines of code to either your
VirtualHost or the apache2.conf (on Debian) or httpd.conf or any
name your Linux or FreeBSD distrubtion users for the Apache
configuration file.
Redirect permanent / https://domain.com/
That's all now just restart Apache.
debian-server:~# /etc/init.d/apache2 restart
There you go your http to https redirect should be now in
action.