1

I want clients to be able to include one of my javascript files on their site like this:

<script src="http://www.example.com/blah.js" ></script>

But I want to actually use php to dynamically create the javascript file/response (I don't want blah.js to actually exist on my server). I am running ubuntu 14.04 and apache 2.4.7. blah.js is the only file I want my server to act on like this. In my php I will check the IP address and create the javascript file/response based on the client site. I want any other javascript file request to act as normal.

Can I use .htaccess to override the directory to have any request for blah.js to be handled by php?

1

2 Answers 2

2

Use rewrite in your htaccess :

RewriteEngine On
RewriteRule ^blah\.js /blah.php [L]

When you will call /blah.js, it will be redirected to blah.php

Sign up to request clarification or add additional context in comments.

1 Comment

I tried this, but I get "403 forbidden" response. I also tried redirecting to the same file (blah.js -> blah.js) as a test, but again I get a "403" response.
1

You can also use .htaccess auto_prepend_file directive to prepend .php file before any of Your other php files come into play, and than use that prepended script to generate whatever You might need.

In Your .htaccess file:

php_value auto_prepend_file "/my/loc/to/php/file.php"

There is also auto_append_file which will pull particular script just after last one manually included by You or application, and do the job after all content is generated, before headers are sent to the client.

Note that php_value directives are not enabled on each shared hosting setup.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.