Quick Htaccess Performance Tweak to Boost SEO

There are many things you can and must do to work on your site’s SEO. Here I will share a quick “trick” to quickly boost your SEO with just a simple piece of code you need to add to your .htaccess file.
I will explain the different parts of this .htaccess snippet so you understand what is added. The main thing in these snippets is site speed’s improvement which is also a SEO booster. A quicker site is a happier visitor and a happier bot. By just using these .htaccess snippets you could boost your Google PageSpeed up to 20 points out of a 100!

Expire Headers

Expire Headers is another site speed and therefore SEO Booster. Expire Headers are added to tell the browser how often it has to fetch files afresh from the server based on a specific expiry data. And as a lot of static files do not change that often it is good to tell it when to do so. This is especially useful for static files like images.

 # BEGIN Expire headers
<IfModule mod_expires.c>
ExpiresActive On
ExpiresDefault "access plus 7200 seconds"
ExpiresByType image/x-icon "access plus 2592000 seconds"
ExpiresByType image/jpeg "access plus 2592000 seconds"
ExpiresByType image/png "access plus 2592000 seconds"
ExpiresByType image/gif "access plus 2592000 seconds"
ExpiresByType application/x-shockwave-flash "access plus 2592000 seconds"
# ExpiresByType text/css "access plus 2592000 seconds"
ExpiresByType text/javascript "access plus 2592000 seconds"
ExpiresByType application/x-javascript "access plus 2592000 seconds"
ExpiresByType text/html "access plus 7200 seconds"
ExpiresByType application/xhtml+xml "access plus 7200 seconds"
</IfModule>
# END Expire headers

Cache Control Headers

Cache Control Headers are added to tell the browser how long files should be cached before they should be loaded anew. This is important to make sure it does not reload files too often, but also to make sure it does fetch them anew after a certain amount of time. This is used by most modern browsers instead of Expire Headers and offers more options to control how long browser keep files and fetch anew

# BEGIN Cache-Control Headers
<IfModule mod_headers.c>
<FilesMatch "\\.(ico|jpe?g|png|gif|swf|gz)$">
Header set Cache-Control "max-age=2592000, public"
</FilesMatch>
<FilesMatch "\\.(css)$">
Header set Cache-Control "max-age=2592000, public"
</FilesMatch>
<FilesMatch "\\.(js)$">
Header set Cache-Control "max-age=2592000, private"
</FilesMatch>
<filesMatch "\\.(html|htm)$">
Header set Cache-Control "max-age=7200, public"
</filesMatch>
# Disable caching for scripts and other dynamic files
<FilesMatch "\.(pl|php|cgi|spl|scgi|fcgi)$">
Header unset Cache-Control
</FilesMatch>
</IfModule>
# END Cache-Control Headers

Gzip

Gzip is one technique Apache uses to compress files using one of its modules. By compressing the files they become smaller and are easier to download by the browser. Browsers deal with the decompressing on the fly.

# Gzip
<ifModule mod_gzip.c>
mod_gzip_on Yes
mod_gzip_dechunk Yes
mod_gzip_item_include file .(html?|txt|css|js|php|pl)$
mod_gzip_item_include handler ^cgi-script$
mod_gzip_item_include mime ^text/.*
mod_gzip_item_include mime ^application/x-javascript.*
mod_gzip_item_exclude mime ^image/.*
mod_gzip_item_exclude rspheader ^Content-Encoding:.*gzip.*
</ifModule>

Deflate

Deflate is just another technique to compress files. Certain Apache servers only use deflate, others only Gzip. That is why we use the ifmodule statement to make sure it only works when the module is available.

#Deflate
<ifmodule mod_deflate.c>
AddOutputFilterByType DEFLATE text/text text/html text/plain text/xml text/css application/x-javascript application/javascript
</ifmodule>

Featured Image: Paul Townsend https://flic.kr/p/oqznyf

Tagged in : Tagged in : ,
Jasper Frumau

Jasper has been working with web frameworks and applications such as Laravel, Magento and his favorite CMS WordPress including Roots Trellis and Sage for more than a decade. He helps customers with web design and online marketing. Services provided are web design, ecommerce, SEO, content marketing. When Jasper is not coding, marketing a website, reading about the web or dreaming the internet of things he plays with his son, travels or run a few blocks.