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?


1 Answer 1


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

Your Answer

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

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