How can mod_rewrite be used to rewrite URLs in PHP?
Mod_rewrite can be used in PHP to rewrite URLs by creating rules in a .htaccess file that map incoming URLs to a specific PHP script or page. This allows for cleaner and more user-friendly URLs that are easier to understand and navigate. By using mod_rewrite, developers can also improve SEO by creating search engine-friendly URLs.
```php
RewriteEngine On
RewriteRule ^products/([0-9]+)/?$ product.php?id=$1 [NC,L]
```
In this example, the rule rewrites a URL like "example.com/products/123" to "example.com/product.php?id=123". The [NC] flag makes the match case-insensitive, and the [L] flag stops processing further rules if this one matches.