What role does .htaccess play in securing directories on a website using PHP?

.htaccess can be used to secure directories on a website by restricting access to certain files or folders. This can be done by setting up authentication requirements such as username and password. By using .htaccess, you can add an extra layer of security to your website and prevent unauthorized access to sensitive information.

// .htaccess file content to secure a directory with basic authentication
AuthType Basic
AuthName "Restricted Area"
AuthUserFile /path/to/.htpasswd
Require valid-user