What role does the .htaccess file play in redirecting URLs in PHP websites?

The .htaccess file is used to configure how a web server handles requests. In the context of redirecting URLs in PHP websites, the .htaccess file can be used to set up URL redirects, rewrite URLs, and handle routing. This is commonly done to create clean URLs, redirect old URLs to new ones, or handle custom routing logic.

RewriteEngine On
RewriteRule ^old-url$ /new-url [R=301,L]