<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine On

# Allow direct access to existing files and directories
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]

# Match pages: /match/{slug}  (works for root + subfolder installs)
RewriteRule ^match/([^.]+)$ match.php?slug=$1 [L,QSA]
RewriteRule ^(.*/)?match/([^.]+)$ match.php?slug=$2 [L,QSA]

# News article pages: /news/{slug}
RewriteRule ^news/([^.]+)$ news.php?article=$1 [L,QSA]
RewriteRule ^(.*/)?news/([^.]+)$ news.php?article=$2 [L,QSA]

# News category pages: /news-category/{slug}
RewriteRule ^news-category/([^.]+)$ news.php?category=$1 [L,QSA]
RewriteRule ^(.*/)?news-category/([^.]+)$ news.php?category=$2 [L,QSA]

# League pages: /league/{slug}
RewriteRule ^league/([^.]+)$ leagues.php?league=$1 [L,QSA]
RewriteRule ^(.*/)?league/([^.]+)$ leagues.php?league=$2 [L,QSA]

# Static pages: /contact, /privacy, /terms, /help, /disclaimer
RewriteRule ^contact/?$ contact.php [L,QSA]
RewriteRule ^privacy/?$ privacy.php [L,QSA]
RewriteRule ^terms/?$ terms.php [L,QSA]
RewriteRule ^help/?$ help.php [L,QSA]
RewriteRule ^disclaimer/?$ disclaimer.php [L,QSA]

# Sitemap XML (optional - also accessible via sitemap.php)
RewriteRule ^sitemap\.xml$ sitemap.php [L]
</IfModule>

# Security: prevent direct access to JSON data files
<FilesMatch "\.json$">
    Order allow,deny
    Deny from all
</FilesMatch>

# Cache static assets
<IfModule mod_expires.c>
ExpiresActive On
ExpiresByType text/css "access plus 7 days"
ExpiresByType application/javascript "access plus 7 days"
ExpiresByType image/png "access plus 30 days"
ExpiresByType image/jpeg "access plus 30 days"
ExpiresByType image/gif "access plus 30 days"
ExpiresByType image/svg+xml "access plus 30 days"
ExpiresByType image/webp "access plus 30 days"
</IfModule>

# Compression
<IfModule mod_deflate.c>
AddOutputFilterByType DEFLATE text/html text/plain text/css application/javascript application/json image/svg+xml
</IfModule>

# Default charset
AddDefaultCharset UTF-8
