<IfModule mod_rewrite.c>
    RewriteEngine On
    
    # Handle CORS - Remove trailing slash from Origin and set proper headers
    <IfModule mod_headers.c>
        # Get the origin and remove trailing slash using regex
        SetEnvIf Origin "^(https?://[^/]+)/?" ORIGIN_NO_SLASH=$1
        
        # Set CORS headers for allowed origins
        # Check if origin matches allowed list (without trailing slash)
        SetEnvIf ORIGIN_NO_SLASH "^https://empdata-sepia\.vercel\.app$" CORS_ALLOW=1
        SetEnvIf ORIGIN_NO_SLASH "^http://localhost(:[0-9]+)?$" CORS_ALLOW=1
        SetEnvIf ORIGIN_NO_SLASH "^https://localhost(:[0-9]+)?$" CORS_ALLOW=1
        
        # Set headers if origin is allowed
        Header always set Access-Control-Allow-Origin "%{ORIGIN_NO_SLASH}e" env=CORS_ALLOW
        Header always set Access-Control-Allow-Methods "GET, POST, PUT, PATCH, DELETE, OPTIONS" env=CORS_ALLOW
        Header always set Access-Control-Allow-Headers "Content-Type, Authorization, X-Requested-With, Accept, Origin, X-XSRF-TOKEN" env=CORS_ALLOW
        Header always set Access-Control-Allow-Credentials "true" env=CORS_ALLOW
        Header always set Access-Control-Max-Age "86400" env=CORS_ALLOW
    </IfModule>
</IfModule>


# php -- BEGIN cPanel-generated handler, do not edit
# Set the “ea-php81” package as the default “PHP” programming language.
<IfModule mime_module>
  AddHandler application/x-httpd-ea-php81 .php .php8 .phtml
</IfModule>
# php -- END cPanel-generated handler, do not edit
