# Enable URL Rewriting
RewriteEngine On

# -----------------------------------------------
# Block Archive Bots Only (User-Agent)
# -----------------------------------------------
SetEnvIfNoCase User-Agent "ia_archiver" BlockArchive
SetEnvIfNoCase User-Agent "Wayback" BlockArchive
SetEnvIfNoCase User-Agent "archive.org_bot" BlockArchive
SetEnvIfNoCase User-Agent "archive" BlockArchive

<Limit GET POST HEAD>
    Order Allow,Deny
    Allow from all
    Deny from env=BlockArchive
</Limit>

# -----------------------------------------------
# Standard SEO & Formatting Rules
# -----------------------------------------------
# Force HTTPS
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R=301,L]

# Remove trailing slashes
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ /$1 [R=301,L]

# Serve .html files without showing the extension
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^\.]+)$ $1.html [NC,L]

# Custom 404 Error Page
ErrorDocument 404 /404.html