# How to redirect HTTP Requests To HTTPS On Apache 2

Source: https://www.hukot.net/community/en/tutorials/how-to-redirect-http-requests-to-https-on-apache-2-11
Updated: 2026-11-25

We will describe how to set up Apache 2, and to redirect unsecure requests (HTTP) to secure (https).

#### Pre-requisites

- You have a Hukot Linux instance running Apache 2.
- Your have *domain name (e.g example.com)* whose DNS A records for "@" and "www" are pointing to the IP of your Hukot machine above.
- Ideally you should also have SSL setup on your instance.

#### Setup redirect

Make sure Apache's mod\_rewrite module is enabled by running

`sudo a2enmod rewrite`

Put below snippet in a *.htaccess* file in your site's root folder.

```
RewriteEngine On

RewriteCond %{HTTPS} !=on

RewriteRule ^/?(.*) https://%{SERVER_NAME}/$1 [R=301,L]
```
