Would you like to learn how to redirect HTTP to HTTPS on Apache? In this tutorial, we are going to show you how to install the Apache server and create a rule to redirect the HTTP traffic to HTTPS on a computer running Linux.
• Ubuntu 20
• Ubuntu 19
• Ubuntu 18
• Apache 2.4.41
In our example, the Apache server is hosting the website WWW.GAMEKING.TIPS.
Copyright © 2018-2021 by Techexpert.tips.
All rights reserved. No part of this publication may be reproduced, distributed, or transmitted in any form or by any means without the prior written permission of the publisher.
Equipment list
The following section presents the list of equipment used to create this tutorial.
As an Amazon Associate, I earn from qualifying purchases.
Apache – Related Tutorial:
On this page, we offer quick access to a list of tutorials related to Apache.
Tutorial Apache – Redirect HTTP to HTTPS
Install the Apache server.
Enable the required Apache modules.
Edit the Apache configuration file for the desired website.
Add the following lines to this configuration file.
Here is the file, before our configuration.
Here is the file, after our configuration.
Restart the Apache service.
In our example, the Apache server will redirect all HTTP requests to HTTPS.
From a remote Linux computer, try to perform an HTTP access.
Here is the command output.
In our example, if a user tries to access the HTTP version of any page, he will be redirected to the HTTPS version of the same page.
Make sure that you have an HTTPS website configured on the Apache server or the connection will be lost.
As an example, here is an Apache configuration file with HTTP and HTTPS enabled.
Congratulations! You successfully configured the HTTP to HTTPS redirection on the Apache server.
Tutorial – Redirect HTTP to HTTPS on Apache
This is another way to redirect HTTP to HTTPS on the Apache server.
Install the Apache server.
Enable the required Apache modules.
Edit the Apache configuration file for the desired website.
Add the following lines to this configuration file.
Here is the file, before our configuration.
Here is the file, after our configuration.
Restart the Apache service.
In our example, the Apache server will redirect all HTTP requests to HTTPS.
From a remote Linux computer, try to perform an HTTP access.
Here is the command output.
In our example, if a user tries to access the HTTP version of any page, he will be redirected to the HTTPS version of the same page.
Make sure that you have an HTTPS website configured on the Apache server or the connection will be lost.
As an example, here is an Apache configuration file with HTTP and HTTPS enabled.
Congratulations! You successfully configured the HTTP to HTTPS redirection on the Apache server.