https://www.vultr.com

The Everywhere Cloud

Deploy an instance.
Accelerate your application.


Redirect Apache HTTP to HTTPS in Debian-based Linux


Once HTTPS is enabled on the web server, remote users can be redirected to this secure protocol by automatically rewriting the URL.

==========

1. Enable the Rewrite module.

user@host: $ sudo a2enmod rewrite

2. Change the current working directory to the Apache site configuration files.

user@host: $ cd /etc/apache2/sites-available

3. BACK UP the default HTTP configuration file for the non-secure site.

user@host: $ sudo cp 000-default.conf 000-default-conf.back

4. Open the default HTTP configuration file.

user@host: $ sudo nano 000-default.conf

5. Replace all contents in the default HTTP configuration with the following code.

# BEGIN CODE

RewriteEngine On
# Enables directives for rewriting.

RewriteCond %{HTTPS} !=on
# Verifies that the connection is not yet in HTTPS.

RewriteRule ^/?(.*) https://%{SERVER_NAME}/$1 [R,L]
# Redirects to the current location but in HTTPS.

# END CODE

6. Restart the web server.

user@host: $ sudo /etc/init.d/apache2 restart

7. Test redirection to HTTPS by accessing HTTP with a simple browser.

user@host: $ lynx http://localhost

==========

Comments

Popular posts from this blog

Enabling HTTPS in Home Assistant

Configuring the FreeBSD Firewall with IPFW

Running Home Assistant on FreeBSD Servers