Image caching (expires) set in .htaccess don't work with subdomains?

Discussion in 'Apache' started by War.Frog, Jul 31, 2010.

  1. #1
    I am using multiple subdomains to serve static images on my vBulletin site and have the following rules in my .htaccess file, but when I run a Page Speed test against it it gives me a list of images without expires on them and all are from subdomains.

    How do I include images from subdomains? My .htaccess file is located in /public_html. I tried creating one in <root> but that had no effect. Any thoughts?


    <ifModule mod_expires.c>
    ExpiresActive On
    ExpiresDefault "access plus 1 seconds"
    ExpiresByType text/html "access plus 1 seconds"
    ExpiresByType image/gif "access plus 2592000 seconds"
    ExpiresByType image/jpeg "access plus 2592000 seconds"
    ExpiresByType image/png "access plus 2592000 seconds"
    ExpiresByType text/css "access plus 604800 seconds"
    ExpiresByType text/javascript "access plus 216000 seconds"
    ExpiresByType application/x-javascript "access plus 216000 seconds"
    </ifModule>
    <ifModule mod_headers.c>
    <filesMatch "\\.(ico|pdf|flv|jpg|jpeg|png|gif)$">
    Header set Cache-Control "max-age=25920000, public"
    </filesMatch>
    <filesMatch "\\.(css)$">
    Header set Cache-Control "max-age=6048000, public"
    </filesMatch>
    <filesMatch "\\.(js)$">
    Header set Cache-Control "max-age=2160000, private"
    </filesMatch>
    <filesMatch "\\.(xml|txt)$">
    Header set Cache-Control "max-age=2160000, public, must-revalidate"
    </filesMatch>
    <filesMatch "\\.(html|htm|php)$">
    Header set Cache-Control "max-age=1, private, must-revalidate"
    </filesMatch>
    </ifModule>
    <ifModule mod_headers.c>
    Header unset ETag
    </ifModule>
    FileETag None
    <ifModule mod_headers.c>
    Header unset Last-Modified
    </ifModule>
    Code (markup):

     
    War.Frog, Jul 31, 2010 IP
  2. tolra

    tolra Active Member

    Messages:
    515
    Likes Received:
    36
    Best Answers:
    1
    Trophy Points:
    80
    #2
    Have you tried adding the .htaccess to each subdomain?
     
    tolra, Aug 2, 2010 IP
  3. War.Frog

    War.Frog Peon

    Messages:
    4
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    I don't know how to do that. When I go into my cPanel I don't see subdomain directories. Any ideas?
     
    War.Frog, Aug 5, 2010 IP
  4. tolra

    tolra Active Member

    Messages:
    515
    Likes Received:
    36
    Best Answers:
    1
    Trophy Points:
    80
    #4
    You would do it via FTP, to find the subdomain folder locations in cPanel click on the subdomains icon then it should list all your subdomains and the path to each e.g. public_html/subdomain1

    Once you know those just connect with your FTP client and upload the .htaccess for image caching to that folder.
     
    tolra, Aug 5, 2010 IP
  5. War.Frog

    War.Frog Peon

    Messages:
    4
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Thanks tolra! I'll give that a run right now.
     
    War.Frog, Aug 5, 2010 IP
  6. CSM

    CSM Active Member

    Messages:
    1,047
    Likes Received:
    25
    Best Answers:
    0
    Trophy Points:
    55
    #6
    Hey there.

    Try to add something like this to your vhost settings:

    
    ExpiresActive On
    ExpiresByType image/png "now plus 365 days"
    ExpiresByType image/jpeg "now plus 365 days"
    ExpiresByType image/gif "now plus 365 days"
    ExpiresByType text/css "now plus 365 days"
    
    Code (markup):
    Now the graphics are NOT loaded if they are not modified.
    We use one domain for css/js/images only that does not send cookies and ofcourse gzip's everything.

    Make sure all modules are loaded (mod_expires, mod_headers and mod_deflate).

    Here is a good explanation:

    http://www.websiteoptimization.com/speed/tweak/cache/

    Have fun experimenting :)

    By the way, I am fine with my vhost settings. Most of the sites I have done have a Page Speed of 91+

    Regards,

    Michael
     
    CSM, Aug 5, 2010 IP