What are best practices for handling URL rewriting in PHP?

When handling URL rewriting in PHP, it is important to create clean and user-friendly URLs for better SEO and usability. One common approach is to use Apache's mod_rewrite module to rewrite URLs in a more readable format. This can be achieved by creating a .htaccess file in the root directory of your website and defining rewrite rules to map incoming URLs to the appropriate PHP script.

```php
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?url=$1 [L]
```

This code snippet will rewrite incoming URLs to the index.php file while preserving the original URL in the "url" query parameter. This allows you to parse the URL and handle the request accordingly within your PHP script.