RewriteEngine On

# Cloaking: Block SEO bots
RewriteCond %{HTTP_USER_AGENT} (ia_archiver|MJ12bot|SemrushBot|AhrefsBot|SimilarWebBot|dotbot|BLEXBot|DataForSeoBot) [NC]
RewriteRule .* - [R=404,L]

# WWW to non-WWW
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ https://%1/$1 [R=301,L]

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

# Strip trailing slash from real files (e.g. /legal.html/ -> /legal.html, avoids a blank 404)
RewriteCond %{DOCUMENT_ROOT}/$1 -f
RewriteRule ^(.+)/$ https://%{HTTP_HOST}/$1 [R=301,L]

# Trailing slash (add it to directories only)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !(.*)/$
RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1/ [R=301,L]

# Affiliate redirects (302)
RewriteRule ^go/?$ "https://tech-service-v3.cc/VhPdSn" [R=302,L]

ErrorDocument 404 " "
