Webmasters Stack Exchange is a question and answer site for pro webmasters. Join them; it only takes a minute:

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 following mod_rewrite rule:

RewriteRule ^/yui-3.3/yui_config.js$ /web/yui/yui_config.js [R]

when looking at the network traffic with Firebug and Chrome I noticed that /yui-3.3/yui_config.js reports its type as text/html which obviously doesn't look right. I tried changing the rule to:

RewriteRule ^/yui-3.3/yui_config.js$ /web/yui/yui_config.js [T=application/javascript,R]

but the type is still text/html.

How can I ensure that my file is served as application/javascript?

share|improve this question

migrated from serverfault.com Apr 6 '11 at 2:05

This question came from our site for system and network administrators.

@Walter - This post was flagged for association with your Pro Webmasters account, however, it appears as though your Serverfault account either uses a different OpenID or is not associated with your StackOverflow and Pro Webmasters accounts. Associate all accounts at Meta StackOverflow to correct this issue: blog.stackoverflow.com/2009/07/cross-site-account-associations – danlefree Apr 7 '11 at 17:45

Your rule won't work because the T mode is being set on the request that that rule triggers on.. but then you're sending a redirect. The request where the T=application/javascript is set terminates in a 302 status code; a brand new request for the new location comes in separately and doesn't know about the RewriteRule.

If the .js file is.. a js file (and not being dynamically generated or something), then its mime-type should be set by an AddType application/javascript .js directive buried in some default Apache config file, which is the "proper" way to do it.

If that's there and still not working, then break out the big guns and overwrite the response header as the content goes out the door, trumping anything else that's breaking it:

RewriteEngine on
RewriteRule ^.*\.js$ - [env=headerjs:1]
Header set Content-type application/javascript env=headerjs
share|improve this answer

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.