# Malaysia Dragons website (static pages + book.php)
# IMPORTANT: this file sits in public_html, and Apache also applies it to the folders inside it
# (createch.my and dev). Every rule below is limited to kldragons.com so those sites are not affected.

<If "%{HTTP_HOST} =~ /^(www\.)?kldragons\.com$/">
  Options -Indexes
  DirectoryIndex index.html index.php
  ErrorDocument 404 /404.html
</If>

RewriteEngine On
# Force HTTPS (kldragons.com only)
RewriteCond %{HTTP_HOST} ^(www\.)?kldragons\.com$ [NC]
RewriteCond %{HTTPS} !=on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
# Clean URLs: /programmes serves programmes.html; /programmes.html redirects to /programmes
RewriteCond %{HTTP_HOST} ^(www\.)?kldragons\.com$ [NC]
RewriteCond %{THE_REQUEST} \s/+(.+?)\.html[\s?] [NC]
RewriteRule ^ /%1 [R=301,L]
RewriteCond %{HTTP_HOST} ^(www\.)?kldragons\.com$ [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME}.html -f
RewriteRule ^(.+?)/?$ $1.html [L]

<IfModule mod_headers.c>
  <If "%{HTTP_HOST} =~ /^(www\.)?kldragons\.com$/">
    Header always set X-Content-Type-Options "nosniff"
    Header always set Referrer-Policy "strict-origin-when-cross-origin"
    Header always set X-Frame-Options "SAMEORIGIN"
  </If>
</IfModule>
