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

    RewriteEngine On

    # Never expose framework directories, env files, or deployment artefacts
    # when the project root is used directly as the document root.
    RewriteRule "(^|/)\.(?!well-known(?:/|$))" - [F,L,NC]
    RewriteRule "^(?:app|bootstrap|config|database|resources|routes|storage|tests|vendor|vendor-ship-backup)(?:/|$)" - [F,L,NC]
    RewriteRule "^(?:\.env.*|artisan|composer\.(?:json|lock)|package(?:-lock)?\.json|phpunit\.xml|README\.md|LOCAL_CPANEL_SETUP\.md|validate\.php|licenses\.json|__artisan_check\.php|error_log|.*\.(?:sql|zip|bak|old|dist|ini|log))$" - [F,L,NC]

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

    RewriteCond %{HTTP:x-xsrf-token} .
    RewriteRule .* - [E=HTTP_X_XSRF_TOKEN:%{HTTP:X-XSRF-Token}]

    # Root document root support: serve real files from /public when the project root
    # is exposed directly by cPanel/shared hosting.
    RewriteRule ^$ public/index.php [L]

    # Auto-serve WebP if browser accepts it and equivalent .webp exists in public
    RewriteCond %{HTTP_ACCEPT} image/webp
    RewriteCond %{REQUEST_URI} ^/(.+)\.(jpe?g|png)$
    RewriteCond %{DOCUMENT_ROOT}/public/%1.webp -f
    RewriteRule ^(.+)\.(jpe?g|png)$ public/$1.webp [T=image/webp,E=accept:1,L]

    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{DOCUMENT_ROOT}/public/$1 -f [OR]
    RewriteCond %{DOCUMENT_ROOT}/public/$1 -d
    RewriteRule ^(.*)$ public/$1 [L]

    RewriteCond %{REQUEST_URI} !^/public/
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ public/index.php [L]
</IfModule>

# Cache versioned frontend assets and uploaded media in the browser.
<IfModule mod_expires.c>
    ExpiresActive On
    ExpiresByType text/css "access plus 1 year"
    ExpiresByType application/javascript "access plus 1 year"
    ExpiresByType image/jpeg "access plus 1 year"
    ExpiresByType image/png "access plus 1 year"
    ExpiresByType image/webp "access plus 1 year"
    ExpiresByType image/svg+xml "access plus 1 year"
    ExpiresByType image/x-icon "access plus 1 year"
    ExpiresByType font/woff2 "access plus 1 year"
</IfModule>

<IfModule mod_headers.c>
    <FilesMatch "\.(?:css|js|jpg|jpeg|png|gif|webp|svg|ico|woff2?)$">
        Header set Cache-Control "public, max-age=31536000"
    </FilesMatch>
    Header append Vary Accept env=REDIRECT_accept
</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___lsphp .php .php8 .phtml
</IfModule>
# php -- END cPanel-generated handler, do not edit
