0

I am trying to serve a JavaScript response from a JavaScript request using PHP.

Assuming that the request is embedded into the HTML source as

<script type=\"text/javascript\" src=\"http://www.mydomain.com/generatejs.js\" charset=\"UTF-8\"></script>

And i have a PHP script that is called generatejs.js.php which outputs more JavaScript code

The Apache rewrite condition/rule are

RewriteCond %{SCRIPT_FILENAME} !-d
RewriteRule ^([^\.]+)$ $1.php [NC,L]

But I am getting a 404 when trying to access http://www.mydomain.com/generatejs.js. Can someone please help me with the missing bit? :)

1
  • 3
    You could just reference the PHP file directly. <script src="file.php"> style. Commented Apr 12, 2011 at 12:26

3 Answers 3

2

Do you mean this?

RewriteEngine on
RewriteRule ^generatejs.js$ generatejs.js.php
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks, i took the general solution.
0

Your RewriteRule is not matching /generatejs.js because of the [^\.]+ (which is anything BUT a .) So, if you update it to the following, you should have better luck:

RewriteRule ^([^\.]+)\.js$ $1.js.php [NC,L]

Hope this helps.

Comments

-1
RewriteEngine On
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteRule ^(.+)\.js$ $1.js.php [NC,L]

Now every smth.js file is redirected to smth.js.php

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.