<IfModule mod_rewrite.c>
    <IfModule mod_negotiation.c>
        Options -MultiViews -Indexes
    </IfModule>

    #     # Allow localhost and production domains

    # <IfModule mod_headers.c>
    #     SetEnvIf Origin "http(s)?://(localhost(:[0-9]+)?|edubeez\.cbeezai\.com|wrteam\.net)$" AccessControlAllowOrigin=$0
        
    #     # Apply CORS headers only to static assets (non-PHP files) to avoid duplication with Laravel's CORS middleware
    #     <FilesMatch "\.(?!php$).*">
    #         Header set Access-Control-Allow-Origin %{AccessControlAllowOrigin}e env=AccessControlAllowOrigin
    #         Header set Access-Control-Allow-Credentials "true" env=AccessControlAllowOrigin
    #         Header set Access-Control-Allow-Methods "GET, POST, PUT, PATCH, DELETE, OPTIONS" env=AccessControlAllowOrigin
    #         Header set Access-Control-Allow-Headers "Content-Type, Authorization, X-Requested-With, Accept, Cache-Control, school-code" env=AccessControlAllowOrigin
    #     </FilesMatch>
    # </IfModule>

    <IfModule mod_headers.c>
    # --- Development CORS for localhost and Production Subdomains ---
    SetEnvIf Origin "http(s)?://(localhost(:[0-9]+)?|staff\.edubeez\.cbeezai\.com|students\.edubeez\.cbeezai\.com)$" AccessControlAllowOrigin=$0

    Header set Access-Control-Allow-Origin %{AccessControlAllowOrigin}e env=AccessControlAllowOrigin
    Header set Access-Control-Allow-Credentials "true" env=AccessControlAllowOrigin
    Header set Access-Control-Allow-Methods "GET, POST, PUT, PATCH, DELETE, OPTIONS" env=AccessControlAllowOrigin
    Header set Access-Control-Allow-Headers "Content-Type, Authorization, X-Requested-With, Accept, Cache-Control, school-code" env=AccessControlAllowOrigin
</IfModule>

    RewriteEngine On

    RewriteCond %{HTTP:school-code} ^(.*)
    RewriteRule .* - [e=HTTP_SCHOOL_CODE:%1]

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

    # 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]
</IfModule>
<IfModule mod_headers.c>
    <FilesMatch "\.(jpg|jpeg|png|gif|webp|svg)$">
        Header set Access-Control-Allow-Origin "*"
    </FilesMatch>
</IfModule>
