# -------------------------------------------------------------
# ✅ Enable rewrite engine
# -------------------------------------------------------------
RewriteEngine On
RewriteBase /

Options -Indexes
<IfModule mod_negotiation.c>
    Options -MultiViews
</IfModule>

Redirect 301 /braun-series-5-shavers/ https://www.shaverinfoformen.com/best-electric-shavers/
Redirect 301 /braun-series-5-shavers.html https://www.shaverinfoformen.com/best-electric-shavers/

Redirect 301 /contact-us/ https://www.shaverinfoformen.com/best-electric-shavers/
Redirect 301 /contact-us.html https://www.shaverinfoformen.com/best-electric-shavers/

Redirect 301 /best-electric-shavers/ https://www.shaverinfoformen.com/
Redirect 301 /best-electric-shavers.html https://www.shaverinfoformen.com/

# -------------------------------------------------------------
# ✅ Redirect non-www to www (no redirect loop)
# -------------------------------------------------------------
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^ https://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

# -------------------------------------------------------------
# ✅ Block Internet Archive bot
# -------------------------------------------------------------
RewriteCond %{HTTP_USER_AGENT} (ia_archiver) [NC]
RewriteRule .* - [F,L]

# -------------------------------------------------------------
# ✅ Add trailing slash only if not file, not dir, and no extension
# -------------------------------------------------------------
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]

RewriteCond %{REQUEST_URI} !\.[A-Za-z0-9]+$
RewriteCond %{REQUEST_URI} !/$
RewriteRule ^ %{REQUEST_URI}/ [R=301,L]

# -------------------------------------------------------------
# ✅ Specific redirections
# -------------------------------------------------------------
RewriteRule ^index\.html$ / [L,R=301]

# -------------------------------------------------------------
# ✅ Pretty URLs (virtual .html paths)
# -------------------------------------------------------------
# Hanya berlaku kalau file .html-nya benar-benar ada
RewriteCond %{REQUEST_FILENAME}.html -f
RewriteRule ^(.+)/$ $1.html [L]

# -------------------------------------------------------------
# ✅ Redirect all known extensions to .html
# -------------------------------------------------------------
RewriteCond %{QUERY_STRING} ^$
RewriteRule ^(.*)\.(shtml|phtml|jhtml|htm|php|aspx|asp|jsp|apk)$ $1.html [L,NC,R=301]

# -------------------------------------------------------------
# ✅ Custom 404 (no redirect, no loop)
# -------------------------------------------------------------
ErrorDocument 404 /404.html

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* - [L,R=404]
