What is the purpose of using a .htaccess file in PHP?

The purpose of using a .htaccess file in PHP is to configure various settings for the Apache web server, such as URL rewriting, access control, and redirection. This file allows you to control how your web server behaves for specific directories or files within your website.

// Sample .htaccess file for URL rewriting
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?url=$1 [QSA,L]