What is the purpose of using .htaccess for redirection in PHP?

Using .htaccess for redirection in PHP allows you to easily redirect users from one URL to another without having to modify your PHP code. This can be useful for redirecting users to a different page, handling 404 errors, or setting up permanent redirects for SEO purposes.

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