<IfModule mod_negotiation.c>
    Options -MultiViews -Indexes
</IfModule>
<IfModule mod_setenvif.c>
  <IfModule mod_headers.c>
    <FilesMatch "(?i)\.(avifs?|bmp|cur|gif|ico|jpe?g|jxl|a?png|svgz?|webp)$">
      SetEnvIf Origin ":" IS_CORS
      Header set Access-Control-Allow-Origin "*" env=IS_CORS
    </FilesMatch>
  </IfModule>
</IfModule>

RewriteEngine On

# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]

RewriteCond %{REQUEST_URI} ^/image/([0-9]+)/files/(.+)/(.+)$
RewriteCond %{DOCUMENT_ROOT}/thumbs/%2/%1_%3 -f
RewriteRule ^(.*)$ /thumbs/%2/%1_%3 [L]

RewriteCond %{REQUEST_URI} ^/files/[0-9]+/album/(.*)$
RewriteCond %{QUERY_STRING} !^pbx$
RewriteRule ^files/[0-9]+/album/(.*)$ - [F,L]

RewriteCond %{REQUEST_URI} ^/upload/[0-9]+/album/(.*)$
RewriteCond %{QUERY_STRING} !^pbx$
RewriteRule ^upload/[0-9]+/album/(.*)$ - [F,L]

# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} (.+)/$
RewriteRule ^ %1 [L,R=301]

# Send Requests To Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
