Redirect http to https with apache via .htaccess

Redirecting your website from http to https is extremely easy using apache. If you your website has been running on http it is important to redirect all incoming http links to https. This way you won’t lose traffic coming from your previously indexed pages and backlinks.

Before redirecting http to https you need to make sure that SSL certificate is properly installed on your server and the mod_rewrite is enabled in Apache.

If you meet the prerequisites above then edit your httpd.conf file and add the following snippet at the very top of your file.

Apache
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}

Please note that you can also redirect single pages from http to https in Apache by inserting the following code snippet in your configuration file or .htaccess file. Do make sure though to update the code with your actual domain name and URL slug.

Apache
RewriteEngine On
RewriteRule ^apache-redirect-http-to-https\.html$ https://www.mydomain.com/my-site-url [R=301,L]