# DirectoryIndex public/index.php

# Options -Indexes

# <IfModule mod_rewrite.c>
#     RewriteEngine On
#     RewriteRule ^$ public/index.php [L]
#     RewriteRule ^(.*)$ public/$1 [L]
# </IfModule>

DirectoryIndex public/index.php

Options -Indexes

<IfModule mod_rewrite.c>
    RewriteEngine On

    # Force HTTP to HTTPS
    RewriteCond %{HTTPS} !=on
    RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

    # Redirect root to Laravel public index
    RewriteRule ^$ public/index.php [L]

    # Send all requests to public folder
    RewriteRule ^(.*)$ public/$1 [L]
</IfModule>

<IfModule mod_headers.c>
    # Prevent clickjacking
    Header always set X-Frame-Options "SAMEORIGIN"

    # Prevent MIME type sniffing
    Header always set X-Content-Type-Options "nosniff"

    # Control referrer information
    Header always set Referrer-Policy "strict-origin-when-cross-origin"

    # Browser permissions control
    Header always set Permissions-Policy "geolocation=(), microphone=(), camera=()"

    # XSS protection for older browsers
    Header always set X-XSS-Protection "1; mode=block"

    # Content Security Policy
    Header always set Content-Security-Policy "default-src 'self'; script-src 'self' 'unsafe-inline' 'unsafe-eval' https:; style-src 'self' 'unsafe-inline' https:; img-src 'self' data: https:; font-src 'self' data: https:; connect-src 'self' https:; frame-src 'self' https:; object-src 'none'; base-uri 'self'; form-action 'self' https:; frame-ancestors 'self'; upgrade-insecure-requests"
</IfModule>

<IfModule mod_headers.c>
    <If "%{HTTPS} == 'on'">
        Header always set Strict-Transport-Security "max-age=31536000; includeSubDomains; preload"
    </If>
</IfModule>