How can PHP be integrated with mod_rewrite for URL manipulation?

To integrate PHP with mod_rewrite for URL manipulation, you can use mod_rewrite to rewrite URLs to a specific PHP file that will handle the requests. This PHP file can then parse the rewritten URL and perform the necessary actions based on the URL parameters.

// .htaccess file to enable mod_rewrite
<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteRule ^(.*)$ index.php?url=$1 [QSA,L]
</IfModule>

// index.php file to handle rewritten URLs
<?php
$url = $_GET['url'];
$urlParts = explode('/', $url);

// Example usage: localhost/myapp/user/123
if($urlParts[0] == 'user' && isset($urlParts[1])) {
    $userId = $urlParts[1];
    // Perform actions based on $userId
}
?>