# ===== TDL.com.my — pretty .html URLs backed by PHP =====
RewriteEngine On

# Force HTTPS
RewriteCond %{HTTPS} off
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

# Force www
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^ https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

# If a visitor requests page.html and a matching page.php exists,
# serve the .php silently (URL stays .html in the address bar).
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} !-f
RewriteCond %{REQUEST_URI} \.html$
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI}::$1 ^(.*?)\.html::\1\.php$ [NC]
RewriteRule ^(.+?)\.html$ $1.php [L]

# Default document
DirectoryIndex index.php index.html

# Block direct access to the partials (they're includes, not pages)
RewriteRule ^partials/ - [F]

# Protect PHPMailer internals
RewriteRule ^PHPMailer/ - [F]
