htaccess: https redirect on Upgrade-Insecure-Requests header
authorMischa POSLAWSKY <perl@shiar.org>
Wed, 20 Oct 2021 22:20:26 +0000 (00:20 +0200)
committerMischa POSLAWSKY <perl@shiar.org>
Tue, 9 Nov 2021 03:14:15 +0000 (04:14 +0100)
Enables encryption on most modern browsers as frequently recommended,
without forcing (old or slow) clients if they don't need or want to.

.htaccess

index 35296eee6c2aa268c8c93ed1801d6b34ce13e66f..f6a07f70f110e35f4d9aa3821d09ecde1f72152a 100644 (file)
--- a/.htaccess
+++ b/.htaccess
@@ -13,6 +13,11 @@ RewriteRule ^(vi(?=m$)|.*)           http://sheet.shiar.nl/$1 [R=301]
 RewriteRule ^vim$                    /vi [R=301]
 RewriteRule ^cc$                     /countries [R=301]
 
 RewriteRule ^vim$                    /vi [R=301]
 RewriteRule ^cc$                     /countries [R=301]
 
+# forward to https protocol if requested
+RewriteCond %{HTTPS}                          =off
+RewriteCond %{HTTP:Upgrade-Insecure-Requests} =1
+RewriteRule (.*)                     https://%{HTTP_HOST}/$1  [L]
+
 # serve vim commands when requesting /digraphs.ex as well
 RewriteRule    ^(digraphs)\.ex(/.*)?$ $1.vim$2
 
 # serve vim commands when requesting /digraphs.ex as well
 RewriteRule    ^(digraphs)\.ex(/.*)?$ $1.vim$2