Msg#: 4594549 posted 11:58 am on Jul 19, 2013 (gmt 0)
I must be using wrong search terms or something but everything I've tried so far did not work.
The last thing I tried was <Files "filename.js"> SetHandler application/x-httpd-php </Files>
It still returns code as plain text. What is the correct rule to use? I've verified it matches the right file by adding an extra header and this was returned correctly. I'm using Apache 2.2.24 and PHP 5.3.25.
Msg#: 4594549 posted 12:36 am on Jul 20, 2013 (gmt 0)
I think the .js to .php rewrite is the way I would go too, personally.
A couple of notes...
1.) I'd make sure to use a server relative path to the file, just to make sure the location is always correct and also add an [L] to the rule, which should always be used unless you know exactly why you don't want it.
RewriteRule ^filename\.js$ /filename.php [L]
2.) I'd make sure I set a header so there was no question a browser interpreted the file and executed it as .js rather than something else. (I've run into issues previously with serving images via PHP to set an expires header and if you don't have the headers set correctly by the PHP file so the browser knows it's an image some browsers "choke" and won't display them.)