# Enable rewrite engine
RewriteEngine On

# Set the base directory
RewriteBase /

# Prevent access to sensitive files
<FilesMatch "^\.ht|db\.php$|config\.php$">
    Order deny,allow
    Deny from all
</FilesMatch>

# Prevent directory listing
Options -Indexes

# Remove PHP extensions
<IfModule mod_rewrite.c>
    # Remove trailing slash if not a directory
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_URI} (.+)/$
    RewriteRule ^ %1 [R=301,L]
    
    # Remove .php extension
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME}\.php -f
    RewriteRule ^(.*)$ $1.php [L]
    
    # Remove .html extension
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME}\.html -f
    RewriteRule ^(.*)$ $1.html [L]
</IfModule>