Mobile app version of vmapp.org
Login or Join
Samaraweera270

: Setting Content Type with mod_rewrite 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

@Samaraweera270

Posted in: #ModRewrite

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?

10.01% popularity Vote Up Vote Down


Login to follow query

More posts by @Samaraweera270

1 Comments

Sorted by latest first Latest Oldest Best

 

@Murray155

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

10% popularity Vote Up Vote Down


Back to top | Use Dark Theme