homepage Welcome to WebmasterWorld Guest from 107.20.34.144
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor 2014
Home / Forums Index / Code, Content, and Presentation / Apache Web Server
Forum Library, Charter, Moderators: Ocean10000 & incrediBILL & phranque

Apache Web Server Forum

    
Can't change Content-Type server header response
wildbest

5+ Year Member



 
Msg#: 4240152 posted 5:01 pm on Dec 8, 2010 (gmt 0)

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.

 

jdMorgan

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



 
Msg#: 4240152 posted 10:45 pm on Dec 8, 2010 (gmt 0)

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

wildbest

5+ Year Member



 
Msg#: 4240152 posted 8:55 pm on Dec 10, 2010 (gmt 0)

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'.

g1smd

WebmasterWorld Senior Member g1smd us a WebmasterWorld Top Contributor of All Time 10+ Year Member



 
Msg#: 4240152 posted 9:30 pm on Dec 10, 2010 (gmt 0)

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.

wildbest

5+ Year Member



 
Msg#: 4240152 posted 9:44 pm on Dec 10, 2010 (gmt 0)

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'?

g1smd

WebmasterWorld Senior Member g1smd us a WebmasterWorld Top Contributor of All Time 10+ Year Member



 
Msg#: 4240152 posted 10:37 pm on Dec 10, 2010 (gmt 0)

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.

jdMorgan

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



 
Msg#: 4240152 posted 1:16 am on Dec 14, 2010 (gmt 0)

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

Jim

g1smd

WebmasterWorld Senior Member g1smd us a WebmasterWorld Top Contributor of All Time 10+ Year Member



 
Msg#: 4240152 posted 2:10 am on Dec 14, 2010 (gmt 0)

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.

jdMorgan

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



 
Msg#: 4240152 posted 2:52 pm on Dec 16, 2010 (gmt 0)

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

wildbest

5+ Year Member



 
Msg#: 4240152 posted 2:01 pm on Dec 18, 2010 (gmt 0)

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.

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / Apache Web Server
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved