# ================== BASE ==================
Options -Indexes -MultiViews +FollowSymLinks
AddDefaultCharset UTF-8

# Forza HTTPS (opzionale)
#RewriteEngine On
#RewriteCond %{HTTPS} !=on
#RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

# MIME playlist
AddType application/x-mpegURL .m3u .m3u8

# Blocca file sensibili
<FilesMatch "^(config\.php|\.env|composer\.(json|lock))$">
  Require all denied
</FilesMatch>

# ================== REWRITE ==================
<IfModule mod_rewrite.c>
RewriteEngine On

# Se il sito è in sottocartella, decommenta e imposta:
# RewriteBase /tua-cartella/

# Non riscrivere se esiste già file o cartella
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]

# ---------- HOME ----------
# /  -> dashboard
RewriteRule ^$ client/dashboard.php [QSA,L]

# ---------- PAGINE PRINCIPALI ----------
RewriteRule ^dashboard/?$        client/dashboard.php   [QSA,L]
RewriteRule ^palinsesto/?$       client/schedule.php    [QSA,L]
RewriteRule ^pricing/?$          client/pricing.php     [QSA,L]
RewriteRule ^prezzi/?$           client/pricing.php     [QSA,L]
RewriteRule ^ticket/?$           client/ticket.php      [QSA,L]
RewriteRule ^assistenza/?$       client/ticket.php      [QSA,L]
RewriteRule ^profilo/?$          client/profilo.php     [QSA,L]
RewriteRule ^login/?$            auth/login.php         [QSA,L]
RewriteRule ^logout/?$           auth/logout.php        [QSA,L]

# ---------- CATEGORIE ----------
RewriteRule ^categoria/([^/]+)/?$  client/category.php?slug=$1  [QSA,L]
RewriteRule ^category/([^/]+)/?$   client/category.php?slug=$1  [QSA,L]

# ---------- LIVE ----------
RewriteRule ^live/([A-Za-z0-9\-_]+)/?$  client/live.php?slug=$1  [QSA,L]
RewriteRule ^live-id/([0-9]+)/?$        client/live.php?id=$1    [QSA,L]

# ---------- PLAYLIST ----------
# /playlist/TOKEN.m3u  o .m3u8
RewriteRule ^playlist/([A-Za-z0-9]+)/?$             client/playlist.php?token=$1        [QSA,L]
RewriteRule ^playlist/([A-Za-z0-9]+)\.(m3u8?)$      client/playlist.php?token=$1        [QSA,L]

# ---------- XTREAM MINI-ADAPTER ----------
RewriteRule ^xtream/get(?:\.php)?$   client/xtream/get.php  [QSA,L]

# ---------- ALIAS COMODI ----------
RewriteRule ^live/?$        client/dashboard.php  [QSA,L]
RewriteRule ^categorie/?$   client/dashboard.php  [QSA,L]

</IfModule>