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]
Comments
Post a Comment