RewriteEngine On

# Remove .php extension from URLs
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php [L]

# Redirect 404 errors to a custom 404 page
ErrorDocument 404 /ims/errors/404.php

# Block access to specific file types
<FilesMatch "\.(htaccess|htpasswd|ini|phar|log|sh|config)$">
    Order Allow,Deny
    Deny from all
</FilesMatch>

# Prevent direct access to functions.php
<Files "functions.php">
    Order Allow,Deny
    Deny from all
</Files>
