4

Can someone explain what the difference is between AddType and AddHandler in htaccess files? I want to make the settings such that I can have a javascript file (.js) be run through the server as though it were a php file (application/x-httpd-php5) but then sent to the user's browser as a (text/javascript) file. How might i configure this?

rolling_codes
  • 15,174
  • 22
  • 76
  • 112
  • 1
    'I want to make the settings such that I can have a javascript file (.js) be run through the server as though it were a php file (application/x-httpd-php5) but then sent to the user's browser as a (text/javascript) file.' Why on earth would you want to do that?!?!? – Caltor Apr 12 '17 at 19:15

2 Answers2

7

AddHandler http://httpd.apache.org/docs/2.0/mod/mod_mime.html#addhandler tells the server how to handle the file type. AddType http://httpd.apache.org/docs/2.0/mod/mod_mime.html#addtype tells the server what MIME type to give the client.

Caltor
  • 2,538
  • 1
  • 27
  • 55
2

I doesn't sound like a great idea to parse all .js files as php. I would suggest using a .htaccess Rewrite directive to map the .js files in question, to your php script.

RewriteRule /phpjs/.* /phpjs/js.php

Then add

header("Content-Type: text/javascript"); 

to your php output.

Captain Giraffe
  • 14,407
  • 6
  • 39
  • 67