Redirect HTTP to HTTPS

Problem: HTTP requests should be redirected automatically to HTTPS

Often there is the need to redirect HTTP traffic to HTTPS - for the UMC for example.

Solution: Redirect all HTTP traffic to HTTPS via UCR

ucr set apache2/force_https=yes

The UCR variable apache2/force_https was introduced as an Erratum for UCS 4.0-2. If you don’t want to redirect all requests or want to configue this for versions prior to UCS 4.0.2, you can use allowoverwrite directive and the RewriteEngine:

ucr set apache2/allowoverride=All

Then create /var/www/.htaccess with the following content:

RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) [https://%{HTTP_HOST}%{REQUEST_URI}

Restart Apache

/etc/init.d/apache2 restart

Webfrontends like Zarafa or Agorum additionally need adjustments in /etc/apache2/httpd.conf:

RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) [https://%{HTTP_HOST}%{REQUEST_URI}
Mastodon