How can mod_rewrite be activated in PHP to avoid Internal Server Errors when using .htaccess files?

When using .htaccess files to rewrite URLs in PHP, mod_rewrite must be activated in the server configuration to avoid Internal Server Errors. This can be done by enabling the mod_rewrite module in Apache and ensuring that AllowOverride is set to All in the server configuration file. Additionally, the RewriteEngine directive must be set to On in the .htaccess file to enable URL rewriting.

<IfModule mod_rewrite.c>
    RewriteEngine On
</IfModule>