# Disable directory browsing
Options -Indexes

# ----------------------------------------------------------------------
# Rewrite engine
# ----------------------------------------------------------------------
<IfModule mod_rewrite.c>
    Options +FollowSymlinks
    RewriteEngine On

    # If your CI4 project is in a subfolder, set it here:
    # RewriteBase /yourfolder/
    # Otherwise leave it disabled.

    # ------------------------------------------------------------------
    # Allow assets, uploads, images, css, js to load normally
    # ------------------------------------------------------------------
    RewriteRule ^(public/)?assets/ - [L]

    # If you also have uploads folder:
    RewriteRule ^(public/)?uploads/ - [L]

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

    # ------------------------------------------------------------------
    # Rewrite "www.example.com -> example.com"
    # ------------------------------------------------------------------
    RewriteCond %{HTTPS} !=on
    RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
    RewriteRule ^ http://%1%{REQUEST_URI} [R=301,L]

    # ------------------------------------------------------------------
    # Route all other requests to index.php
    # ------------------------------------------------------------------
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php/$1 [L,NC,QSA]

    # ------------------------------------------------------------------
    # Ensure Authorization header is passed
    # ------------------------------------------------------------------
    RewriteCond %{HTTP:Authorization} .
    RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
</IfModule>

<IfModule !mod_rewrite.c>
    ErrorDocument 404 index.php
</IfModule>

# Disable server signature
ServerSignature Off
