# Disable directory browsing
Options -Indexes

<IfModule mod_rewrite.c>
    RewriteEngine On
    
    # This tells Apache everything starts from /home/
    RewriteBase /home/

    # 1. Handle Trailing Slashes (Exclude the base folder itself)
    # This prevents the rule from fighting with the /home/ directory
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_URI} ^/home/(.+)/$
    RewriteRule ^(.*)/$ /home/$1 [L,R=301]

    # 2. Force Non-WWW (Optional, ensure this matches your SSL setup)
    RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
    RewriteRule ^ http://%1%{REQUEST_URI} [R=301,L]

    # 3. Send Requests To Front Controller
    # If the file or directory doesn't exist, send it to index.php
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ /home/index.php/$1 [L]
</IfModule>

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

ServerSignature Off