https://www.vultr.com

The Everywhere Cloud

Deploy an instance.
Accelerate your application.


Redirect Apache HTTP to HTTPS in FreeBSD


After enabling HTTPS on the web server in FreeBSD, remote users can be redirected to this secure protocol by automatically rewriting the URL.

==========

1. Log in to "root". Regular users must be part of the "wheel" group in order to do this.

user@host: $ su -

2. Open the Apache main configuration file.

root@host: # ee /usr/local/etc/apache24/httpd.conf

3. Find and uncomment the following Apache directives.

# BEGIN CODE
# ...

LoadModule rewrite_module libexec/apache24/mod_rewrite.so
# Apache rewrite engine

Include etc/apache24/Includes/*.conf
# Custom configuration files

# ...
# END CODE

4. Create a custom config file in the "Includes" directory.

root@host: # ee /usr/local/etc/apache24/Includes/myrewrite.conf

5. Place the following code in the custom config file.

# 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.

root@host: # service apache24 restart

==========

Comments

Popular posts from this blog

Enabling HTTPS in Home Assistant

Running Home Assistant on FreeBSD Servers

Configuring the FreeBSD Firewall with IPFW