Options -Indexes
Options -MultiViews
DirectoryIndex index.php index.html

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /altoukhi/

# Redirect /altoukhi/index.php to /altoukhi/ (preserve query string)
RewriteCond %{THE_REQUEST} \s/altoukhi/index\.php[\s?] [NC]
RewriteRule ^index\.php$ /altoukhi/ [R=301,L]

# Explicitly route directory roots to their index.php
# Root of /altoukhi -> index.php
RewriteRule ^$ index.php [L]
# Language roots -> their index.php
RewriteRule ^ar/?$ ar/index.php [L]
RewriteRule ^en/?$ en/index.php [L]

# Add trailing slash for real directories (so /altoukhi/ar -> /altoukhi/ar/)
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^(.+[^/])$ $1/ [L,R=301]

# Pass through existing files and directories
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule . - [L]

# Fallback: route anything else to index.php so PHP can handle 404
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php [L]
</IfModule>
