What is the purpose of .htaccess in PHP web development?

The purpose of .htaccess in PHP web development is to configure various settings for the Apache web server that hosts the PHP application. This includes setting up URL rewriting, redirecting URLs, setting custom error pages, restricting access to certain directories, and more.

# Example of redirecting all traffic to HTTPS
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]