Installing an SSL certificate on your Apache server is not the end of the process of securing your website. In fact it’s really only the beginning. Your website is still being served via HTTP — this means you’re going to need to re-write some URLs, create some redirects, and force HTTPS. This means you’ll need to redirect HTTP to HTTPS in Apache.
Fortunately, we’re here to help. In this guide we’ll discuss how to take care of all three in Apache to redirect permanently your site to the HTTPS protocol.
So, before we get started let’s assume you’ve already purchased and installed an SSL certificate on your Apache server. You’ll also need to have your SSL and rewrite modules active on Apache.
Save Up to 82% on RapidSSL DV SSL Certificates
Protect your website within few minutes with a Domain Validated (DV) SSL Certificate.
How to Redirect HTTP to HTTPS on an Apache Server
There are two primary ways that you could redirect HTTP to HTTPS in Apache:
- You could use mod_rewrite in Apache, or
- You can use the more secure virtual host redirect method.
We always think it’s best to go with the more secure methods. As such, let’s talk about redirecting your site to HTTPS using your virtual host:
- Open your virtual host.
- Paste this in:
<VirtualHost *:80>
ServerName www.yourdomain.com
Redirect permanent / https://www.yourdomain.com/
</VirtualHost>
<VirtualHost _default_:443>
ServerName www.yourdomain.com
DocumentRoot / usr/local/apache2/htdocs
SSLEngine On
. . .
</VirtualHost>
- Save.
- Go on living your life.