Apache Cache headers and 301

Discussion in 'Apache' started by varun077, Mar 4, 2010.

  1. #1
    I am facing a problem related to file caching on apache web server.
    I have following header in config file:

    ExpiresActive On
    # expire images after a month in the client's cache
    ExpiresByType image/gif A2592000
    ExpiresByType image/jpg A2592000
    ExpiresByType image/png A2592000
    # HTML, Javascript and CSS documents are good for a week from the
    # time they were changed
    ExpiresByType text/html M604800
    ExpiresByType text/javascript M604800
    ExpiresByType text/css M604800



    But I also have some redirects after this. For e.g. for images I have following redirect:

    Redirect permanent /site/images/ http://mysite.com/images/
    Code (markup):

    When I check headers for an image, I am getting this:

    HTTP/1.1 301 Moved Permanently
    Date: Thu, 04 Mar 2010 08:24:32 GMT
    Server: Apache/2.2.8 (Ubuntu) PHP/5.2.4-2ubuntu5.5 with Suhosin-Patch
    Location: <image url>
    Content-Length: 413
    Connection: close
    Content-Type: text/html; charset=iso-8859-1
    
    HTTP/1.1 200 OK
    Date: Thu, 04 Mar 2010 08:24:32 GMT
    Server: Apache/2.2.8 (Ubuntu) PHP/5.2.4-2ubuntu5.5 with Suhosin-Patch
    Last-Modified: Mon, 01 Oct 2007 19:31:56 GMT
    ETag: "16a91-225-43b737d482300"
    Accept-Ranges: bytes
    Content-Length: 549
    Cache-Control: max-age=2592000
    Expires: Sat, 03 Apr 2010 08:24:32 GMT
    Connection: close
    Content-Type: image/gif
    Load Time : 0.046 seconds 
    Code (markup):
    I understand 301 is for redirect of image path and 200 OK is for image. Following lines of response above make it clear that server is sending future date of expiry to browser (IE 6 in this case).

    Cache-Control: max-age=2592000
    Expires: Sat, 03 Apr 2010 08:24:32 GMT


    My question is "why does browser need to go to server at all when it knows it has image in the cache"? How can I prevent 301 calls and how do I know if browser is caching the image (on looking at Expires directive)?
     
    varun077, Mar 4, 2010 IP