Installing mod_pagespeed for performance increase on RHEL/Centos for Apache

mod_pagespeed is an Open Source module published by Google which automatically configures various different optimisations within your configuration to enable faster site performance. Given the benefits and ease at which it can be installed, it should be high on the priority list to configure.

Continue reading “Installing mod_pagespeed for performance increase on RHEL/Centos for Apache”

Configuring content caching for speed optimisation

By default, Apache does not apply browser caching headers to any content it serves to users. Although this is desirable if you are testing or developing a website, the reality is that for the majority of the content you serve, it does not change frequently. This is especially the case for images, javascript and CSS files on a production website. Enabling caching on the browser side will mean that users make far fewer subsequent requests when navigating to additional pages, as they no longer have to make a repeated request for a resource already downloaded. End result: faster page loads and lower server and bandwidth requirements.

Continue reading “Configuring content caching for speed optimisation”

Using .htaccess to force redirection of all traffic to HTTPS

If you have implemented an SSL certificate on your site and want to easily redirect ALL requests to HTTPS (which is security best practice and easily avoids unsightly protocol mismatch errors within a users browser), you can use a very simple addition to your .htaccess file to complete this.

How to

Simply add the following to your .htaccess file:

RewriteEngine On 
 RewriteCond %{HTTPS} !on 
 RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}

You will then be forced by Apache to load resources using HTTPS.


If this does not take effect, you will need to examine whether your host is disabling .htaccess files within your environment (which is fairly rare).

You will also need to spend some time confirming that all resources are either being loaded using relative links from your code or are not being called from external services on HTTP to avoid any content protocol mismatch errors for your users.

Enabling Apache content compression for performance increase

One simple and highly recommended way to improve performance of sites, especially those with large Javascript and CSS files is to enable compression of these files when they are sent to users. By default this behaviour is not enabled by default within Apache, however there is a simple block of code that can be added to your configuration to enable it and achieve compression rates of over 75% on your page load, which given the drop off rate of site visitors for slow loading pages (as reflected by Google’s ranking algorithm) is a very easy win.

Although the below works in the majority of cases, it is important to test your site after completing the change to ensure there are no issues and you may need to make some changes to the files you are allowing to be compressed if you do see any issues.

How to

First off, check that mod_deflate is enabled within your Apache configuration. The easiest way to do this is to output the configuration of Apache and check for “deflate_module” using the following command:

# apachectl -M | grep deflate


If this does not show, you will need to pre-append “LoadModule deflate_module modules/” to the below content.

The below directives should be added to your Apache configuration. The best way to manage this is to create a new configuration file within the Apache directory (the below locations may need to be adjusted for your environment).

# vi /etc/httpd/conf.d/deflate.conf


Then add the below:

<IfModule mod_mime.c>
AddType application/x-javascript .js
AddType text/css .css
<IfModule mod_deflate.c>
AddOutputFilterByType DEFLATE application/atom_xml application/javascript application/rss+xml application/x-javascript application/x-httpd-php application/xhtml+xml application/xml image/svg+xml image/x-icon text/css text/html text/plain text/richtext text/x-component text/xml text/xsd text/xsl
<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
<IfModule mod_headers.c>
Header append Vary User-Agent env=!dont-vary


Once this file is saved, check that the Apache configuration is still valid, before restarting Apache.

# apachectl -t
Syntax OK

# service httpd restart
Stopping httpd: [ OK ]
Starting httpd: [ OK ]


Now this is complete, you can test your site to check for compression and what should be a drastically improved load time.