Results 1 to 4 of 4

Thread: .htaccess expiry - exclude directory?

  1. #1
    Join Date
    Mar 2005
    Location
    Western Australia
    Posts
    148
    Thanks
    24
    Thanked 4 Times in 4 Posts

    Default .htaccess expiry - exclude directory?

    Hi guys

    I am wanting to add expiry settings for our images, scripts, css etc and that has been done fine enough via

    Code:
    <IfModule mod_expires.c>
    ExpiresActive On
    ExpiresByType image/gif "access plus 1 year"
    ExpiresByType image/jpeg "access plus 1 year"
    ExpiresByType image/png "access plus 1 year"
    ExpiresByType text/css "access plus 1 year"
    ExpiresByType text/javascript "access plus 1 year"
    ExpiresByType application/x-javascript "access plus 1 year"
    </IfModule>
    But this applies the expires to everything but I need a couple of directories to not be added to the expiry as images are replaced often. So how do I tell it to exclude image in X directory?

    Thanks
    1st rule of web development - use Firefox and Firebug
    2nd rule - see the first rule
    --
    I like Smilies

  2. #2
    Join Date
    Apr 2008
    Location
    So.Cal
    Posts
    3,643
    Thanks
    63
    Thanked 516 Times in 502 Posts
    Blog Entries
    5

    Default

    a more local .htaccess rule will override rules inherited from parent directories, so put a new .htaccess file in the desired directory, with your desired expiry.

  3. #3
    Join Date
    Mar 2005
    Location
    Western Australia
    Posts
    148
    Thanks
    24
    Thanked 4 Times in 4 Posts

    Default

    Ok so how do I tell it NOT to expire png's for example in a separate directory?

    Do I have the directory specific .htaccess like the above but remove the image expires? Thus since that htaccess file does not say expire it does not expire even though the one above it does?

    Sorry a bit confused
    1st rule of web development - use Firefox and Firebug
    2nd rule - see the first rule
    --
    I like Smilies

  4. #4
    Join Date
    Apr 2008
    Location
    So.Cal
    Posts
    3,643
    Thanks
    63
    Thanked 516 Times in 502 Posts
    Blog Entries
    5

    Default

    no: the parent rule will apply to child directories unless there is a local rule that contradicts it.
    so, set a .htaccess rule for a very short expiry to override the year-long rule in the parent directory:
    Code:
    ExpiresByType image/png "access plus 1 seconds"
    ## etc.
    so, basically, you're changing the local rule to force images to expire right after they're served.

    Edit:

    Also, if you ever need to force a new version of a particular file that's not set to expire yet, you can add a nonsense query string to its url:

    www.example.com/path/to/file.html?v=whatever

    the query string isn't being used to pass any values (in fact, you can do this with images or css files as well), but it tricks the browser into thinking it's a different file so it won''t use the cached version. from css-tricks

    Last edited by traq; 04-08-2010 at 03:10 AM.

  5. The Following User Says Thank You to traq For This Useful Post:

    gwmbox (04-08-2010)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •