htaccess: https redirect on Upgrade-Insecure-Requests header
[sheet.git] / .htaccess
1 Options        -MultiViews -Indexes
2 DirectoryIndex index.plp
3 DirectorySlash Off
4
5 RewriteEngine  on
6 RewriteBase    /
7
8 # redirect from old vim-only subdomain
9 RewriteCond %{HTTP_HOST}             ^vim?\.shiar\.\w+$
10 RewriteRule ^(vi(?=m$)|.*)           http://sheet.shiar.nl/$1 [R=301]
11
12 # redirect old locations
13 RewriteRule ^vim$                    /vi [R=301]
14 RewriteRule ^cc$                     /countries [R=301]
15
16 # forward to https protocol if requested
17 RewriteCond %{HTTPS}                          =off
18 RewriteCond %{HTTP:Upgrade-Insecure-Requests} =1
19 RewriteRule (.*)                     https://%{HTTP_HOST}/$1  [L]
20
21 # serve vim commands when requesting /digraphs.ex as well
22 RewriteRule    ^(digraphs)\.ex(/.*)?$ $1.vim$2
23
24 # add .plp if a file exists with .plp appended (topdir only)
25 RewriteCond    %{REQUEST_FILENAME}     !-f
26 RewriteCond    %{DOCUMENT_ROOT}/$1.plp  -f
27 RewriteRule    ^/*([^/]+)(.*)           $1.plp$2
28
29 # replace jpeg images by webp alternatives if supported
30 RewriteCond    %{HTTP_ACCEPT}           \bimage/webp
31 RewriteCond    %{DOCUMENT_ROOT}/$1.webp -f
32 RewriteRule    (.*)\.jpg$               $1.webp
33
34 # allow browsers to cache for upto a month
35 <IfModule headers_module>
36 <FilesMatch "\.(?:css|js|json)$">
37 Header set Cache-Control "max-age=2592000"
38 Header set Access-Control-Allow-Origin "*"
39 </FilesMatch>
40 </IfModule>
41