Welcome to WebmasterWorld Guest from 54.167.252.62

Forum Moderators: Ocean10000 & incrediBILL & phranque

Message Too Old, No Replies

Can't change Content-Type server header response

     
5:01 pm on Dec 8, 2010 (gmt 0)

5+ Year Member



I'm 302 redirecting requests for .axd files to be pulled from IIS server. Apache headers are properly showing 'Location' but the default 'Content-Type: text/html'. I have to change it to 'application/x-javascript' or 'application/javascript'. Redirection, however, takes about 2 seconds during which time some browsers continue to parse content as if they expect 'text/html' media type. Parsing would be done differently and more smoothly if browser knows 'application/javascript' type should be expected. I hope you get the idea.

I've tried using:

mod_mime
AddType application/javascript .axd

mod_headers
<FilesMatch "\.axd$">
Header set Content-Type "application/javascript"
</FilesMatch>

mod_rewrite [T] flag
[L,R=302,T=application/javascript] // it's Apache 1.3

Nothing works. Content-Type server header still is 'text/html'. What else should I try?

I'm about to give up and apply rewrite to process.php page where redirect and header change takes place by:
header("Location: http://www.example.com/");
header('Content-Type: application/javascript');
But this option would add at least a second to the load time.
10:45 pm on Dec 8, 2010 (gmt 0)

WebmasterWorld Senior Member jdmorgan is a WebmasterWorld Top Contributor of All Time 10+ Year Member



Not sure I understand this. Redirects don't use Content-Type headers, because a redirect response contains no response-body...

The content-type goes with the content -- the redirected-to 'page' or resource.

Also, I'm not sure why you are redirecting to the IIS server; this sounds like a job for a reverse-proxy, not a redirect.

Jim
8:55 pm on Dec 10, 2010 (gmt 0)

5+ Year Member



Redirects don't use Content-Type headers, because a redirect response contains no response-body...

I'm sorry for confusion. To see response headers I use 'Live HTTP headers' add-on. This is what they show in response to 'GET /ExampleScript.axd?d=tyugyYhiiWsnObeDq3PMcVgoVc9' request:

HTTP/1.1 302 Found
Date: Fri, 10 Dec 2010 20:33:55 GMT
Server: Apache
Location: http://www.example.com/ExampleScript.axd?d=tyugyYhiiWsnObeDq3PMcVgoVc9
Keep-Alive: timeout=15, max=100
Connection: Keep-Alive
Transfer-Encoding: chunked
Content-Type: text/html; charset=iso-8859-1

I can't find a way to either remove 'Content-Type' header or change it to 'application/x-javascript'.
9:30 pm on Dec 10, 2010 (gmt 0)

WebmasterWorld Senior Member g1smd is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month



The resource returns "text/html" because the resource at the requested location is not a script, it's a redirect to another location.

That other location should return the correct header when, and only when, that other location is requested in a new and separate HTTP transaction.

The 302 redirect is dangerous. I am guessing that it should really be a 301 redirect.
9:44 pm on Dec 10, 2010 (gmt 0)

5+ Year Member



Thank you, g1smd. The resource at the requested location is not a script but it is no 'text/html' either.

I know that the other location will return the correct header. My question was is there a way I can remove the 'Content-Type' header or change it to 'application/javascript'?
10:37 pm on Dec 10, 2010 (gmt 0)

WebmasterWorld Senior Member g1smd is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month



No. There is no need to do so. The correct response at the final URL is sufficent.

The redirect response could return a human-readable HTML page like:
<html><head><title>Redirect</title></head>
<body><p>This page has moved. It's now located at <a href="www.example.com/somepage">www.example.com/somepage</a></p></body></html>

In that case, the page IS text/html.
1:16 am on Dec 14, 2010 (gmt 0)

WebmasterWorld Senior Member jdmorgan is a WebmasterWorld Top Contributor of All Time 10+ Year Member



But note that even though a redirect *could* return a content-body (as above), no modern browsers ever show these.

Jim
2:10 am on Dec 14, 2010 (gmt 0)

WebmasterWorld Senior Member g1smd is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month



Sure, the browser doesn't show it, but such pages occasionally turn up in search results and in searchengine cache, and in that case the human readable message and link is useful! I was just explaining why "text/html" is correct, and why anything else is less than useful.
2:52 pm on Dec 16, 2010 (gmt 0)

WebmasterWorld Senior Member jdmorgan is a WebmasterWorld Top Contributor of All Time 10+ Year Member



I intended only to point out that there's no pressing need to return a content-body with a 30x response code, and that the content-type returned with a 30x response code is not very important (in that context).

It is the content-type of the redirected-to URL that matters.

Jim
2:01 pm on Dec 18, 2010 (gmt 0)

5+ Year Member



Thank you g1smd and jdMorgan. I'm still struggling to understand what is going on. If I use Chrome Developer Tools on the Console tab there is a warning "Resource interpreted as script but transferred with MIME type text/html". Every time this warning is activated, the target server is again 302 redirecting (browser request for the .axd resource file), but this time to a 404 page.
 

Featured Threads

Hot Threads This Week

Hot Threads This Month