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.

Tutorial Apache - Redirect HTTP to HTTPS

Install the Apache server.

Copy to Clipboard

Enable the required Apache modules.

Copy to Clipboard

Edit the Apache configuration file for the desired website.

Copy to Clipboard

Add the following lines to this configuration file.

Copy to Clipboard

Here is the file, before our configuration.

Copy to Clipboard

Here is the file, after our configuration.

Copy to Clipboard

Restart the Apache service.

Copy to Clipboard

In our example, the Apache server will redirect all HTTP requests to HTTPS.

From a remote Linux computer, try to perform an HTTP access.

Copy to Clipboard

Here is the command output.

Copy to Clipboard

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.

Copy to Clipboard

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.

Copy to Clipboard

Enable the required Apache modules.

Copy to Clipboard

Edit the Apache configuration file for the desired website.

Copy to Clipboard

Add the following lines to this configuration file.

Copy to Clipboard

Here is the file, before our configuration.

Copy to Clipboard

Here is the file, after our configuration.

Copy to Clipboard

Restart the Apache service.

Copy to Clipboard

In our example, the Apache server will redirect all HTTP requests to HTTPS.

From a remote Linux computer, try to perform an HTTP access.

Copy to Clipboard

Here is the command output.

Copy to Clipboard

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.

Copy to Clipboard

Congratulations! You successfully configured the HTTP to HTTPS redirection on the Apache server.