# ============================================================
# Ball Connect â€” .htaccess for the /ballconnect/ folder
#
# Place this file directly inside the ballconnect folder
# (alongside index.html) on your Apache server. It only affects
# this folder, so it won't interfere with GamesJi.com's existing
# site-wide rules at the domain root.
#
# Note: this only works if your host has AllowOverride enabled
# for this directory (true on almost all shared hosting; ask
# your host if rules below don't seem to apply).
# ============================================================

# ---------- Correct MIME type for the PWA manifest ----------
<IfModule mod_mime.c>
  <Files "manifest.json">
    ForceType application/manifest+json
  </Files>
</IfModule>

# ---------- Let the service worker control this whole folder ----------
<IfModule mod_headers.c>
  <Files "sw.js">
    Header set Service-Worker-Allowed "/ballconnect/"
  </Files>
</IfModule>

# ---------- Caching strategy ----------
# The app shell and service worker must stay revalidate-able so
# players always get your latest update; icons/images rarely
# change, so they're safe to cache for longer.
<IfModule mod_headers.c>
  <FilesMatch "^(index\.html|sw\.js|manifest\.json)$">
    Header set Cache-Control "no-cache, must-revalidate"
  </FilesMatch>
  <FilesMatch "\.(png|jpg|jpeg|webp|svg|ico)$">
    Header set Cache-Control "public, max-age=604800, immutable"
  </FilesMatch>
</IfModule>

# ---------- Compress text-based files for faster loading ----------
<IfModule mod_deflate.c>
  AddOutputFilterByType DEFLATE text/html text/css application/javascript application/json application/xml image/svg+xml
</IfModule>

# ---------- Force HTTPS ----------
# Service workers (required for PWA install) only run on HTTPS.
# Skip/remove this block if GamesJi.com already forces HTTPS
# site-wide -- it's harmless either way (won't cause a loop),
# but no need to duplicate it if the root .htaccess handles it.
<IfModule mod_rewrite.c>
  RewriteEngine On
  RewriteCond %{HTTPS} off
  RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

  # Keep one canonical URL with a trailing slash: /ballconnect -> /ballconnect/
  RewriteCond %{REQUEST_URI} ^/ballconnect$ [NC]
  RewriteRule ^ %{REQUEST_URI}/ [L,R=301]
</IfModule>

# ---------- Directory listing ----------
# Temporarily left enabled (no "Options -Indexes" here) so that if
# index.html isn't being found for some reason, you'll see a normal
# file listing instead of an unhelpful 403 -- easier to debug. Once
# the site is confirmed working, you can add "Options -Indexes" back
# on its own line to disable listings again.