Tweak .htaccess to Increase Website Speed to Improve SEO (Search Engine Optimization)

Tweak and Edit .htaccess to Increase Website Speed

Edit .htaccess to Increase Website Speed to Improve SEO in Apache Server

.htaccess should be as follows:

< 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"

ExpiresByType text/css "access 1 month”

# Javascript
ExpiresByType application/javascript "access plus 1 year"

< /IfModule >

# compress text, html, javascript, css, 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

How To Tweak .htaccess To Increase Website Speed to Improve SEO Ranking Without Gzip or Deflate

.htaccess should be as follows:

AddType x-mapp-php6 .html .htm .php .js
 ExpiresActive On
 ExpiresByType image/gif "access plus 2 weeks"
 ExpiresByType image/jpeg "access plus 2 weeks"
 ExpiresByType image/png "access plus 2 weeks"
 ExpiresByType image/ico "access plus 2 weeks"
 ExpiresByType text/css "access plus 2 weeks"
 ExpiresByType text/javascript "access plus 2 weeks"
 ExpiresByType application/x-javascript "access plus 2 weeks"

php.ini should be as follows:

 zlib.output_compression = On
 zlib.output_compression_level = 9

You can check your website speed at google page speed insights at I recommend you to check your website speed before and after you put the code so you can see the difference.


By tweaking and editing .htaccess, we enabled compression and leveraged browser caching. We can do compression in three ways. Gzip, deflate or compressing with php. The first example shows how we did compression by using deflate. If we can’t do compression by using gzip or deflate, we can still do compression by using php. Second example shows how we did compression by using php. As you see on both of these examples, we also set an expiry date or a maximum age in the HTTP headers for static resources instructs the browser to load previously downloaded resources from local disk rather than over the network. Therefore, website speed increases.

The review of enabling compressing and leveraging browser caching is 2 of the Google Page Speed Insights elements. I will review other 8 Google Page Speed Insights elements on my next post to increase the website speed to improve SEO.

Leave a Reply

Your email address will not be published. Required fields are marked *