How can the .htaccess file be utilized to enhance security and prevent unauthorized access to files in a PHP application?

The .htaccess file can be utilized to enhance security by restricting access to certain files or directories within a PHP application. This can help prevent unauthorized users from accessing sensitive information or executing malicious scripts.

# Deny access to .htaccess file
<Files .htaccess>
  Order allow,deny
  Deny from all
</Files>

# Deny access to specific file types
<FilesMatch "\.(inc|php|phps|php5|phtml|php3|php4|sh|pl|py)$">
  Order allow,deny
  Deny from all
</FilesMatch>

# Deny directory listing
Options -Indexes