Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

If I serve a file named image.jpg the header content-type is sent as image/jpeg, but if I make a softlink named image that points to image.jpg the content-type is sent as text/plain.

Is there a way to send the same content type as if it were reading the original file?

share|improve this question

1 Answer 1

up vote 3 down vote accepted

The content-type is determined by the mappings in the MIME-Magic file supplied with apache. This has a mapping for *.jpg to image/jpeg.

You can force the content-type inside a container, like so:

<Location /URI/of/images>
   ForceType image/jpeg
</Location>

http://httpd.apache.org/docs/2.2/mod/core.html#forcetype

share|improve this answer
    
Thanks! But not all the images are jpeg. Although if I can't find a solution I guess I could make 3 directories for png/gif/jpg and iterate them with RewriteRule. But I would need to change the code that generates the symlinks and I would want to avoid that. –  Zequez Feb 24 '12 at 11:46
    
If there are specific filetypes, you can add a <FilesMatch> block for each of the real locations (which you must provide access to regardless, since the files are symlinked) –  adaptr Feb 24 '12 at 12:02
    
The problem is that the images and symlinks are generated dynamically so that wouldn't be practical. –  Zequez Feb 24 '12 at 12:23
    
In the other hand I just need to return the Content-Type of an image, it actually doesn't matter the exact type, so I guess ForceType is going to be enough. –  Zequez Feb 24 '12 at 12:26

Your Answer

 
discard

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.