<IfModule mod_rewrite.c>
  RewriteEngine on

  RewriteCond %{HTTP_HOST} ^www\.(.*) [NC]
  RewriteRule ^(.*)$       https://%1%{REQUEST_URI} [R=301,L]
  RewriteCond %{HTTPS}     off
  RewriteRule ^(.*)$       https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

  RewriteBase /

  RewriteCond %{REQUEST_URI} !/$
  RewriteCond %{REQUEST_URI} !\.[^/\.]+$
  RewriteRule ^(.*)$ $1/ [R=301,L]

  # URL miss
  RewriteRule ^posts/alpha_alflayla_senyasabou_cyou_omatome_pack/ /posts/alpha-alflayla-senyasabou-cyou-omatome-pack/ [R=301,L]

  # Double post
  RewriteRule ^posts/25344241/ /posts/25344237/ [R=301,L]

  # to Sveltekit
  RewriteRule ^posts/+X-Reversal/ /posts/X-Reversal/ [R=301,L]

  # Articles with only flickr images
  RewriteRule ^posts/2256647/ /ranking/ [R=301,L]
  RewriteRule ^posts/2131822/ /ranking/ [R=301,L]
  RewriteRule ^posts/2112727/ /ranking/ [R=301,L]
  RewriteRule ^posts/2049701/ /ranking/ [R=301,L]
  RewriteRule ^posts/2030198/ /ranking/ [R=301,L]
  RewriteRule ^posts/1807893/ /ranking/ [R=301,L]
  RewriteRule ^posts/45307037/ /ranking/ [R=301,L]
  RewriteRule ^posts/48642261/ /ranking/ [R=301,L]
  RewriteRule ^posts/15698913/ /ranking/ [R=301,L]
  RewriteRule ^posts/15934726/ /ranking/ [R=301,L]
  RewriteRule ^posts/21031973/ /ranking/ [R=301,L]
  RewriteRule ^posts/2188304/ /ranking/ [R=301,L]

  ErrorDocument 404 /404/index.html

  RewriteCond %{HTTP:Accept-Encoding} gzip
  RewriteCond %{REQUEST_URI} (\.json)$
  RewriteCond %{REQUEST_FILENAME}\.gz -s
  RewriteRule .+ %{REQUEST_URI}.gz [L]

  <files *.json.gz>
      AddType "application/json;charset=utf-8" .gz
      AddEncoding x-gzip .gz
  </files>
</IfModule>

# https://jyn.jp/apache-setting-deflate/
# <IfModule mod_deflate.c>
#     DeflateCompressionLevel 1
#     <IfModule mod_filter.c>
#         FilterDeclare COMPRESS
#         FilterProvider COMPRESS DEFLATE "%{CONTENT_TYPE} =~ m#^text/#i"
#         FilterProvider COMPRESS DEFLATE "%{CONTENT_TYPE} =~ m#^application/(atom\+xml|javascript|json|rss\+xml|xml|xhtml\+xml)#i"
#         FilterProvider COMPRESS DEFLATE "%{CONTENT_TYPE} =~ m#^image/(svg\+xml|x-icon|vnd\.microsoft\.icon)#i"
#         FilterChain COMPRESS
#         FilterProtocol COMPRESS DEFLATE change=yes;byteranges=no
#         #BrowserMatch ^Mozilla/4 gzip-only-text/html
#         #BrowserMatch ^Mozilla/4\.0[678] no-gzip
#         #BrowserMatch \bMSI[E] !no-gzip !gzip-only-text/html
#         #Header append Vary Accept-Encoding env=!dont-vary
#     </IfModule>
# </IfModule>

