Search code examples
.htaccessaddhandler

What is the difference between AddHandler and AddType in htaccess files


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?


Solution

  • 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.