Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have the folowing rewrite rule in my .htaccess file

RewriteRule     ^js_([A-Za-z0-9\.\_\-]{1,50})\.php$  libjs/misc/$1.js

so js_messages.php url links to libjs/misc/messages.js file

It's working good, but now i need to execute php code from some .js files.

How can i do that? Thanks.

P.S. sorry for my english

share|improve this question
up vote 1 down vote accepted

Depending on your server setup and what the hosting provider lets you do I would use SetHandler to tell apache to send .js files to the php module:

Something like this:

<FilesMatch "\.php$|\.js$">
    SetHandler application/x-httpd-php

Can you edit the configuration file for Apache? is this a shared webhosting? can you overwrite any setting from .htaccess ?

share|improve this answer
Thank you! This is right answer, but it works only for php as an apache module, i have php as a fastcgi configuration and my solution is little different – dmeleshko Nov 1 '13 at 12:39

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.