# ==============================
# .htaccess — boomingslots-casino.com (root + only /privacy-policy)
# ==============================

<IfModule mod_rewrite.c>
RewriteEngine On

# ---------- FORCE HTTPS (301 http -> https) ----------
RewriteCond %{HTTPS} !=on [OR]
RewriteCond %{HTTP:X-Forwarded-Proto} =http
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

# ---- BLOCK SPECIFIC USER-AGENT (Chrome/44) ----
# RewriteCond %{HTTP_USER_AGENT} Chrome/44
# RewriteRule .* - [F,L]

# ---------- REWRITE ----------

# 0) Не чіпати службові файли в корені
RewriteRule ^robots\.txt$ - [L]
RewriteRule ^sitemap\.xml$ - [L]

# 0.05) ЗРОБИТИ 404.html "НЕІСНУЮЧОЮ" ДЛЯ ВСІХ (і для Google теж)
# Якщо хтось зайде на /404.html напряму -> одразу 404
RewriteRule ^404\.html$ - [R=404,L]

# 0.1) Не чіпати будь-які існуючі файли або папки
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]

# ---------- ROOT: clean URL ----------

# 1) Прибрати index.html із зовнішніх запитів (корінь)
RewriteCond %{THE_REQUEST} \s/+(.*)index\.html?\s [NC]
RewriteRule ^ /%1 [R=301,L]

# 2) .html -> clean (301) тільки для privacy-policy
RewriteCond %{THE_REQUEST} \s/+privacy-policy\.html(\s|\?) [NC]
RewriteRule ^privacy-policy\.html$ /privacy-policy [R=301,L]

# 3) «Хвости» після дозволеної сторінки
RewriteRule ^privacy-policy/.+$ /privacy-policy [R=301,L,NC]

# 4) Clean URL → внутрішнє підключення .html
RewriteRule ^privacy-policy/?$ privacy-policy.html [L,NC]

# ---------- FALLBACK ----------
RewriteRule ^ - [R=404,L]

</IfModule>


# ---------- ERROR DOCUMENTS ----------
ErrorDocument 404 /404.html


# ---------- OPTIONS ----------
Options -Indexes
DirectoryIndex index.html


# ---------- SECURITY HEADERS ----------
<IfModule mod_headers.c>
  Header unset X-Robots-Tag
  Header always set Strict-Transport-Security "max-age=31536000; includeSubDomains"
  Header always set X-Content-Type-Options "nosniff"
  Header always set X-Frame-Options "DENY"
  Header always set Referrer-Policy "strict-origin-when-cross-origin"

  # CSP
  Header always set Content-Security-Policy "default-src 'self'; script-src 'self' 'unsafe-inline' 'unsafe-eval' blob: https://cdn.ampproject.org https://unpkg.com https://www.google.com https://www.gstatic.com https://cdn.skypack.dev https://cdn.jsdelivr.net https://analytics.ahrefs.com https://static.cloudflareinsights.com; worker-src 'self' blob:; connect-src 'self' https://ipwho.is https://formspree.io https://cdn.ampproject.org https://analytics.ahrefs.com https://static.cloudflareinsights.com; style-src 'self' 'unsafe-inline' https://unpkg.com https://fonts.googleapis.com; img-src 'self' data: https://www.gstatic.com https://i.ytimg.com https://i.vimeocdn.com; font-src 'self' data: https://fonts.gstatic.com; frame-src 'self' https://www.youtube.com https://player.vimeo.com https://demogamesfree.pragmaticplay.net https://*.pragmaticplay.net; child-src 'self' https://www.youtube.com https://player.vimeo.com https://demogamesfree.pragmaticplay.net https://*.pragmaticplay.net; frame-ancestors 'self';"

  # 🚫 404 сторінку забороняємо індексувати навіть якщо її хтось знайде
  <Files "404.html">
    Header set X-Robots-Tag "noindex, nofollow, nosnippet"
  </Files>

  # ✔ HTML кешуємо — 4 години (14400 сек)
  <FilesMatch "\.(html?|htm)$">
    Header set Cache-Control "public, max-age=14400, must-revalidate"
    Header unset Pragma
    Header unset Expires
  </FilesMatch>
</IfModule>


# ---------- CACHING / COMPRESSION ----------
<IfModule mod_expires.c>
  ExpiresActive On
  ExpiresByType text/html "access plus 4 hours"
  ExpiresByType image/jpg  "access plus 1 year"
  ExpiresByType image/jpeg "access plus 1 year"
  ExpiresByType image/gif  "access plus 1 year"
  ExpiresByType image/png  "access plus 1 year"
  ExpiresByType image/webp "access plus 1 year"
  ExpiresByType image/svg+xml "access plus 1 year"
  ExpiresByType text/css "access plus 1 month"
  ExpiresByType application/javascript "access plus 1 month"
  ExpiresByType image/x-icon "access plus 1 year"
  ExpiresDefault "access plus 1 month"
</IfModule>

<IfModule mod_deflate.c>
  SetEnvIfNoCase Request_URI "^/robots\.txt$" no-gzip
  AddOutputFilterByType DEFLATE text/html text/xml text/css text/javascript application/javascript application/x-javascript application/xml
</IfModule>

<IfModule mod_mime.c>
  AddType text/javascript .js
  AddType text/typescript .ts
</IfModule>

# ---------- TYPE для robots.txt ----------
<Files "robots.txt">
  ForceType text/plain
  Header unset Content-Encoding
  SetEnv no-gzip 1
</Files>


# === Long-term static cache (1 year + immutable) ===
<IfModule mod_expires.c>
  ExpiresActive On
  ExpiresByType image/avif "access plus 1 year"
  ExpiresByType image/webp "access plus 1 year"
  ExpiresByType image/svg+xml "access plus 1 year"
  ExpiresByType image/png "access plus 1 year"
  ExpiresByType image/jpeg "access plus 1 year"
  ExpiresByType image/gif  "access plus 1 year"
  ExpiresByType text/css   "access plus 1 year"
  ExpiresByType application/javascript "access plus 1 year"
  ExpiresByType font/woff2 "access plus 1 year"
  ExpiresByType font/woff  "access plus 1 year"
</IfModule>

<IfModule mod_headers.c>
  <FilesMatch "\.(avif|webp|svg|png|jpe?g|gif|css|js|woff2?|mjs)$">
    Header set Cache-Control "public, max-age=31536000, immutable"
  </FilesMatch>

  # ✔ HTML кеш 4 години
  <FilesMatch "\.(html?)$">
    Header set Cache-Control "public, max-age=14400, must-revalidate"
    Header unset Pragma
    Header unset Expires
  </FilesMatch>

  Header unset ETag
  FileETag MTime Size
</IfModule>
