1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

.htaccess Edit For Cache, and Now Images Won't Load

Discussion in 'Apache' started by aleo1203, Apr 18, 2012.

  1. #1
    I've been trying to implement a caching system for my site, an example page being here. As you can see from the code, there should be images appearing under each of the linked armoire plans, but they aren't loading anymore. So this is how I got to this point.

    To begin with, my .htaccess file was blank. So I found a caching system over at askapache.com and saved this code into my domain's .htaccess file.
    # year
    <FilesMatch "\.(ico|pdf|flv|jpg|jpeg|png|gif|swf|mp3|mp4)$">
    Header set Cache-Control "public"
    Header set Expires "Fri, 01 Jun 2012 20:00:00 GMT"
    Header unset Last-Modified
    #2 hours
    <FilesMatch "\.(html|htm|xml|txt|xsl)$">
    Header set Cache-Control "max-age=7200, must-revalidate"
    <FilesMatch "\.(js|css)$">
    SetOutputFilter DEFLATE
    Header set Expires "Fri, 01 Jun 2012 20:00:00 GMT"
    Code (markup):
    That didn't work. I checked the headers on websniffer and it said no-cache. So I reverted back to the blank .htaccess file. I searched some more and checked my site and noticed that the images weren't loading. I went to my other computer and checked my site and the images were loading fine, so I assumed it was just the cache on my laptop. Ok, fine. I found some new code to try out and saved this to my .htaccess,

    # Turn on the Expires engine
    ExpiresActive On
    # Expires after a month client accesses the file
    ExpiresByType image/jpeg A2592000
    ExpiresByType image/gif A2592000
    ExpiresByType image/png A2592000
    ExpiresByType image/x-icon A2592000
    ExpiresByType text/plain A2592000
    # Good for one week
    ExpiresByType application/x-javascript M604800
    ExpiresByType text/css M604800
    ExpiresByType text/html M604800
    Code (markup):

    That didn't work either. I again reverted back to a blank .htaccess file but this time the images won't load at all. My site is being hosted at webhostinghub.com, cpanel (build 4), apache 2.2.22. I assumed they have mod_expires enabled because a post in their support forum stated that it was enabled for a particular user, but I am going to check on that. Thanks for any help.
    aleo1203, Apr 18, 2012 IP
  2. scylla

    scylla Notable Member

    Likes Received:
    Best Answers:
    Trophy Points:
    Use this. From my guide here.

    #Deny attempts to view the Htaccess file.
    <Files .htaccess>
    Order allow,deny
    Deny from all
    # BEGIN Browser Caching/Headers
    <IfModule mod_mime.c>
        AddType text/css .css
        AddType text/richtext .rtf .rtx
        AddType image/svg+xml .svg .svgz
        AddType text/plain .txt
        AddType text/xsd .xsd
        AddType text/xsl .xsl
        AddType video/asf .asf .asx .wax .wmv .wmx
        AddType video/avi .avi
        AddType image/bmp .bmp
        AddType application/java .class
        AddType video/divx .divx
        AddType application/msword .doc .docx
        AddType application/x-msdownload .exe
        AddType image/gif .gif
        AddType application/x-gzip .gz .gzip
        AddType image/x-icon .ico
        AddType image/jpeg .jpg .jpeg .jpe
        AddType application/vnd.ms-access .mdb
        AddType audio/midi .mid .midi
        AddType video/quicktime .mov .qt
        AddType audio/mpeg .mp3 .m4a
        AddType video/mp4 .mp4 .m4v
        AddType video/mpeg .mpeg .mpg .mpe
        AddType application/vnd.ms-project .mpp
        AddType application/vnd.oasis.opendocument.database .odb
        AddType application/vnd.oasis.opendocument.chart .odc
        AddType application/vnd.oasis.opendocument.formula .odf
        AddType application/vnd.oasis.opendocument.graphics .odg
        AddType application/vnd.oasis.opendocument.presentation .odp
        AddType application/vnd.oasis.opendocument.spreadsheet .ods
        AddType application/vnd.oasis.opendocument.text .odt
        AddType audio/ogg .ogg
        AddType application/pdf .pdf
        AddType image/png .png
        AddType application/vnd.ms-powerpoint .pot .pps .ppt .pptx
        AddType audio/x-realaudio .ra .ram
        AddType application/x-shockwave-flash .swf
        AddType application/x-tar .tar
        AddType image/tiff .tif .tiff
        AddType audio/wav .wav
        AddType audio/wma .wma
        AddType application/vnd.ms-write .wri
        AddType application/vnd.ms-excel .xla .xls .xlsx .xlt .xlw
        AddType application/zip .zip
    <IfModule mod_expires.c>
        ExpiresActive On
        ExpiresByType text/css A2628000
        ExpiresByType text/richtext A3600
        ExpiresByType image/svg+xml A3600
        ExpiresByType text/plain A3600
        ExpiresByType text/xsd A3600
        ExpiresByType text/xsl A3600
        ExpiresByType video/asf A2628000
        ExpiresByType video/avi A2628000
        ExpiresByType image/bmp A2628000
        ExpiresByType application/java A2628000
        ExpiresByType video/divx A2628000
        ExpiresByType application/msword A2628000
        ExpiresByType application/x-msdownload A2628000
        ExpiresByType image/gif A2628000
        ExpiresByType application/x-gzip A2628000
        ExpiresByType image/x-icon A2628000
        ExpiresByType image/jpeg A2628000
        ExpiresByType application/vnd.ms-access A2628000
        ExpiresByType audio/midi A2628000
        ExpiresByType video/quicktime A2628000
        ExpiresByType audio/mpeg A2628000
        ExpiresByType video/mp4 A2628000
        ExpiresByType video/mpeg A2628000
        ExpiresByType application/vnd.ms-project A2628000
        ExpiresByType application/vnd.oasis.opendocument.database A2628000
        ExpiresByType application/vnd.oasis.opendocument.chart A2628000
        ExpiresByType application/vnd.oasis.opendocument.formula A2628000
        ExpiresByType application/vnd.oasis.opendocument.graphics A2628000
        ExpiresByType application/vnd.oasis.opendocument.presentation A2628000
        ExpiresByType application/vnd.oasis.opendocument.spreadsheet A2628000
        ExpiresByType application/vnd.oasis.opendocument.text A2628000
        ExpiresByType audio/ogg A2628000
        ExpiresByType application/pdf A2628000
        ExpiresByType image/png A2628000
        ExpiresByType application/vnd.ms-powerpoint A2628000
        ExpiresByType audio/x-realaudio A2628000
        ExpiresByType application/x-shockwave-flash A2628000
        ExpiresByType application/x-tar A2628000
        ExpiresByType image/tiff A2628000
        ExpiresByType audio/wav A2628000
        ExpiresByType audio/wma A2628000
        ExpiresByType application/vnd.ms-write A2628000
        ExpiresByType application/vnd.ms-excel A2628000
        ExpiresByType application/zip A2628000
    <IfModule mod_deflate.c>
        <IfModule mod_setenvif.c>
            BrowserMatch ^Mozilla/4 gzip-only-text/html
            BrowserMatch ^Mozilla/4\.0[678] no-gzip
            BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
            BrowserMatch \bMSI[E] !no-gzip !gzip-only-text/html
        <IfModule mod_headers.c>
            Header append Vary User-Agent env=!dont-vary
        <IfModule mod_filter.c>
            AddOutputFilterByType DEFLATE text/css application/x-javascript text/html text/richtext image/svg+xml text/plain text/xsd text/xsl text/xml image/x-icon
    <FilesMatch "\.(css|CSS|)$">
        <IfModule mod_headers.c>
            Header set Pragma "public"
            Header append Cache-Control "public, must-revalidate, proxy-revalidate"
        FileETag MTime Size
        <IfModule mod_headers.c>
             Header set X-Powered-By "Step by Step guide to speed up your VB4 (forum only)"
    <FilesMatch "\.(rtf|rtx|svg|svgz|txt|xsd|xsl|RTF|RTX|SVG|SVGZ|TXT|XSD|XSL|)$">
        <IfModule mod_headers.c>
            Header set Pragma "public"
            Header append Cache-Control "public, must-revalidate, proxy-revalidate"
        FileETag MTime Size
        <IfModule mod_headers.c>
             Header set X-Powered-By "Step by Step guide to speed up your VB4 (forum only)"
    <FilesMatch "\.(asf|asx|wax|wmv|wmx|avi|bmp|class|divx|doc|docx|exe|gif|gz|gzip|ico|jpg|jpeg|jpe|mdb|mid|midi|mov|qt|mp3|m4a|mp4|m4v|mpeg|mpg|mpe|mpp|odb|odc|odf|odg|odp|ods|odt|ogg|pdf|png|pot|pps|ppt|pptx|ra|ram|swf|tar|tif|tiff|wav|wma|wri|xla|xls|xlsx|xlt|xlw|zip|ASF|ASX|WAX|WMV|WMX|AVI|BMP|CLASS|DIVX|DOC|DOCX|EXE|GIF|GZ|GZIP|ICO|JPG|JPEG|JPE|MDB|MID|MIDI|MOV|QT|MP3|M4A|MP4|M4V|MPEG|MPG|MPE|MPP|ODB|ODC|ODF|ODG|ODP|ODS|ODT|OGG|PDF|PNG|POT|PPS|PPT|PPTX|RA|RAM|SWF|TAR|TIF|TIFF|WAV|WMA|WRI|XLA|XLS|XLSX|XLT|XLW|ZIP)$">
        <IfModule mod_headers.c>
            Header set Pragma "public"
            Header append Cache-Control "public, must-revalidate, proxy-revalidate"
        FileETag MTime Size
        <IfModule mod_headers.c>
             Header set X-Powered-By "Step by Step guide to speed up your VB4 (forum only)"
    # End Browser Caching/Headers
    Code (markup):
    scylla, Apr 19, 2012 IP