Search code examples
apache.htaccesspagespeedyslowgtmetrix

Gtmetrix : Add Expires headers on my .htaccess, Apache Server ,, here are the results showing the issue and my .htaccess file configuration


im working on optimizing my website that is hosted on an Apache web server, after working on my css files (combining them in one file ... ) and img alt, optimizing images size and enabling gzip for browsers ,... i got always YSlow Score below to 58% and PageSpeed equal to 80% ,, please need help !

the image is showing the components that said that they don't have a "far-future expiration date" (click here)

this is my .htaccess file where i put some configuration that i found as a solution on Gtmetrix.com

<IfModule mod_rewrite.c>
############################################
## enable rewrites

    Options +FollowSymLinks
    RewriteEngine on
#    RewriteCond %{HTTP_HOST}!^www\.exemple\.com

    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-l
#    RewriteRule .* - [S=1]
    RewriteRule .* index.php [L]
#    RewriteRule (.*)http://www.exemple.com/$1 [R=301,L]

</IfModule>


#******************Non www redirect – Canonical Issue******************





#************"Compressing files / caching"
# compress text, HTML, JavaScript, CSS, and XML
AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/xml
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE application/xml
AddOutputFilterByType DEFLATE application/xhtml+xml
AddOutputFilterByType DEFLATE application/rss+xml
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE application/x-javascript

# remove browser bugs
BrowserMatch ^Mozilla/4 gzip-only-text/html
BrowserMatch ^Mozilla/4\.0[678] no-gzip
BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
Header append Vary User-Agent



<IfModule mod_expires.c>
# Enable expirations
ExpiresActive On
# Default directive
ExpiresDefault "access plus 1 month"
# My favicon
ExpiresByType image/x-icon "access plus 1 year"
# Images
ExpiresByType image/gif "access plus 1 month"
ExpiresByType image/png "access plus 1 month"
ExpiresByType image/jpg "access plus 1 month"
ExpiresByType image/jpeg "access plus 1 month"
# CSS
ExpiresByType text/css "access plus 1 month"
# Javascript
ExpiresByType application/javascript "access plus 1 year"
</IfModule>



<IfModule mod_headers.c>
    <FilesMatch "\.(bmp|css|flv|gif|ico|jpg|jpeg|js|pdf|png|svg|swf|tif|tiff|woff|eot|ttif)(\.gz)?$">

        Header set Expires "Thu, 22 Mar 2018 20:00:00 GMT"
        Header unset Etag
        FileETag None

        Header set cache-control "max-age=2592000, public"
    </FilesMatch>
</IfModule>

Solution

  • i saw the screenshot that you got from Gtmetrix, i think that all is alright with you, and those files are externals,so you can't optimize them :) ! Check other recommendations and try to fix them to get a good YSlow Score, Best Regards Bro :)