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

    RewriteEngine On

    # Force HTTPS (optional, remove if using behind proxy like ngrok)
    RewriteCond %{HTTPS} off
    RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

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

    # Handle Front Controller (index.php)
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.php [L]
</IfModule>

<IfModule mod_headers.c>
    # Remove X-Frame-Options for your own content (if necessary)
    Header always unset X-Frame-Options

    # Allow Shopify to embed your app (adjust CSP policy for storefront, not admin)
    Header always set Content-Security-Policy "frame-ancestors 'self' https://*.myshopify.com https://admin.shopify.com"

    # OPTIONAL: Allow cross-origin for Shopify admin interactions (adjust as needed)
    # Header set Access-Control-Allow-Origin "*"
    # Header set Access-Control-Allow-Headers "Origin, X-Requested-With, Content-Type, Accept"
</IfModule>

# Fallback for missing .htaccess functionality
DirectoryIndex index.php
