How to rewrite a js file in .htaccess

I want to count the number of requests to a file via a rewrite to a php script. I am using the following code in the .htaccess file for this redirect:

Option 1:

RewriteEngine On  
RewriteBase / 
RewriteCond %{REQUEST_FILENAME} -f
RewriteCond %{REQUEST_URI} test.js$ [NC]
RewriteRule ^ /handler.php?filename=%{REQUEST_FILENAME} [L]

Option 2:

RewriteEngine On  
RewriteBase / 
RewriteRule (.*test.js$) /handler.php?filename=$1 [L]

But this redirection doesn’t happen, it outputs the normal contents of the test.js file, without involving the handler.php file