<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /

    # ========================================================
    # 1. ROUTE TO LARAVEL BACKEND (APIs, Uploads, Images, and Storage)
    # ========================================================
    # Added "storage" here so Laravel can serve its storage files
    RewriteCond %{REQUEST_URI} ^/(api|uploads|images|storage) [NC]
    RewriteRule ^(.*)$ Backend/public/$1 [L]

    # ========================================================
    # 2. ROUTE TO REACT FRONTEND
    # ========================================================
    RewriteCond %{REQUEST_URI} !^/Frontend/ [NC]
    RewriteCond %{REQUEST_URI} !^/Backend/ [NC]
    
    # If it's a physical file inside Frontend, serve it
    RewriteCond %{DOCUMENT_ROOT}/Frontend/$1 -f [OR]
    RewriteCond %{DOCUMENT_ROOT}/Frontend/$1 -d
    RewriteRule ^(.*)$ Frontend/$1 [L]

    # Otherwise, send it to React's index.html to handle the routing
    # Added "storage" here too so React ignores it
    RewriteCond %{REQUEST_URI} !^/(api|uploads|images|storage) [NC]
    RewriteCond %{REQUEST_URI} !^/Backend/ [NC]
    RewriteCond %{REQUEST_URI} !^/Frontend/ [NC]
    RewriteRule ^(.*)$ Frontend/index.html [QSA,L]
</IfModule>
