How can mod_rewrite be used to prevent access to a specific folder on a website using PHP?

To prevent access to a specific folder on a website using PHP, you can use mod_rewrite in your .htaccess file to redirect any requests to that folder to a different location or display an error message. This can help protect sensitive information or restrict access to certain parts of your website.

RewriteEngine On
RewriteRule ^specific-folder/.*$ /error-page.php [L]