What are the best practices for handling CSS, images, and JS files when using RewriteRule in PHP?

When using RewriteRule in PHP to create clean URLs, it's important to handle CSS, images, and JS files properly to ensure they are still accessible. One common approach is to check if the requested file exists on the server before applying the RewriteRule. If the file exists, serve it directly; if not, redirect the request to your PHP script. This way, static files can be served efficiently without unnecessary processing.

RewriteEngine On

# Check if the requested file exists
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

# RewriteRule to redirect requests to your PHP script
RewriteRule ^(.*)$ index.php?url=$1 [QSA,L]