You could just serve the script from a php file - this works fine from ASP so should be equally fine for PHP.
If you are likely to distribute your code to others or install it on systems you don't control this has an advantage over mod_rewrite in that you don't have the extra installation step (adding the rewrite controls to the apache config or .htaccess, which might not work if the host does not have mod_rewrite enabled).
I recall there were problems with some older browsers not liking javascipt being served without the right mime type, so make sure you set this with
One major issue to be aware of, whether you use mod_rewrite or php more directly, is of course that if the php code does anything with input from the query-string or the app's database you need to ensure, like all your code, that said data is properly screened to avoid potential injection and XSS attacks.
Another, more minor, issue to be aware of is cache control. The PHP processor will default to marking the output as always needing to be re-requested, where for a plain JS file Apache may return a "304 not modified" response if the browser indicates it has previously made the same request, which if the script being returned does not change could be a waste of your bandwidth and make the response seem slower to remote users. This is a non-issue if your app is always hosted on HTTPS (as nothing served via HTTPS should be cached anyway) but might be a consideration for large blocks of script severed over HTTP. If this could be a problem for you there are ways you can manipulate cache control to regain its advantage.