1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Parse .js files with PHP [with .htaccess directive]

Discussion in 'Apache' started by rohan_shenoy, Dec 3, 2008.

  1. #1
    This is something that is bothering me. I have been able to get this to work on my localhost(development server) but it does not work on the production server.

    Production server is a PHP enabled linux server, whereas development server is a windows-based(WAMPserver 2.0 package)

    I am using the following .htaccess directive, which works successfully on windows-based dev. server, but not on linux based production server.

    
    <FilesMatch "\.(js)$">
    AddHandler application/x-httpd-php .js
    </FilesMatch>
    
    Code (markup):
    I also tried the AddType directive, but then it serves the .JS file as a download and still does not parse the PHP within it!

    Please help. Thanks in advance.
    -Rohan.
     
    rohan_shenoy, Dec 3, 2008 IP
  2. joebert

    joebert Well-Known Member

    Messages:
    2,150
    Likes Received:
    88
    Best Answers:
    0
    Trophy Points:
    145
    #2
    Find where "*.php" files are being set to get parsed as PHP and copy the directive used there into your htaccess or add .js to it where it is. It's going to be in one of your httpd.conf, mods-available folder, <virtualhost> container, or somewhere along those lines.

    You might need to specify the PHP version in the type, Godaddy is an example of where this is required.

    AddHandler x-httpd-php5 .js
    Code (markup):
    You might also want to make sure you're able to make "FileInfo" overrides in htaccess by looking in your <virtualhost> container.
     
    joebert, Dec 7, 2008 IP
  3. rohan_shenoy

    rohan_shenoy Active Member

    Messages:
    441
    Likes Received:
    20
    Best Answers:
    0
    Trophy Points:
    60
    #3
    Hi Joebert,
    Thanks for the reply. Actually, I wanted to get it to work urgently, and my cheap webhost was not so helpful, so I changed the extension of all .js file to .php. Now it works, but still I will remember to use your solution when I am in such a situation in future.

    Thanks for your time. :)
     
    rohan_shenoy, Dec 10, 2008 IP