# Enable MP3 file serving with proper MIME type
AddType audio/mpeg .mp3

# Enable gzip compression for audio files
<IfModule mod_deflate.c>
    AddOutputFilterByType DEFLATE audio/mpeg
</IfModule>

# Set cache headers for audio files (cache for 1 week)
<IfModule mod_expires.c>
    ExpiresActive On
    ExpiresByType audio/mpeg "access plus 1 week"
</IfModule>

# Security headers
<IfModule mod_headers.c>
    # Allow cross-origin requests for audio files
    Header set Access-Control-Allow-Origin "*"
    Header set Access-Control-Allow-Methods "GET, HEAD, OPTIONS"
    Header set Access-Control-Allow-Headers "Range, Content-Type"
    
    # Security headers
    Header set X-Content-Type-Options nosniff
    Header set X-Frame-Options DENY
</IfModule>

# Block access to non-MP3 files
<FilesMatch "^(?!.*\.mp3$).*$">
    Require all denied
</FilesMatch>

# Enable range requests for audio streaming
<IfModule mod_headers.c>
    Header set Accept-Ranges bytes
</IfModule>

# Optimize for mobile streaming
<IfModule mod_rewrite.c>
    RewriteEngine On
    
    # Handle HEAD requests for audio existence checking
    RewriteCond %{REQUEST_METHOD} ^HEAD$
    RewriteCond %{REQUEST_FILENAME} -f
    RewriteRule ^(.+\.mp3)$ - [L]
</IfModule>