Hi I have been trying so hard to do the following on htaccess but it does not seem to work.
can someone out there help me?
AddType application/x-httpd-php .js
I tried the php4,php5 version all the things I could find on google but I had no luck.
what have I missed?
in my file.js
are the following...
<?php
$(document).ready();//jquery/javascript
?>
I am expect a php fatal error but I see exactly the above as plain text.
If you want to do this using just .htaccess configuration (who wants to set the headers in every PHP file?):
<FilesMatch "\.css$">
SetHandler application/x-httpd-php
Header set Content-type "text/css"
</FilesMatch>
<FilesMatch "\.js$">
SetHandler application/x-httpd-php
Header set Content-type "application/javascript"
</FilesMatch>
Try:
<FilesMatch "\.(js)$">
AddHandler application/x-httpd-php .js
</FilesMatch>
If I am correct, your PHP JS file has to be served with a header of content-type: application/x-javascript, otherwise it is not interpreted as JS.
Header("content-type: application/x-javascript");
If you're trying to make PHP work in Javascript files you can simply rename the Javascript to javascript_file.js.php
and have PHP work inside of that.
You will have no problem including that into your page.
`
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With