Using .htaccess to improve SEO.

In my previous article where I showed how to SEO optimize a Joomla instalment, link here: SEO for Joomla. The article became quite large and I could not dive deeper into the SEO aspect for .htaccess therefor I will dive deeper into .htaccess. When it comes to web hosting or any kind of website .htaccess will be very important in terms of security what also ties into a higher SEO score. The .htaccess file has been around since the dawn of time when it comes to HTTP/WWW protocols any can change the behaviour of your site. While configuring an Apache server through the http.conf itself it is rarely you will have access to that file on shared hosting solutions. But do not worry the .htaccess file is almost as powerful at the http.conf file but it can be tricky to work with. However in the long run understanding, this file will make your life much easier, and your website much better in the long run. For Joomla users I have a pre-made .htaccess file you can download, the website you current viewing is configured with the same file. --> Joomla .htaccess File <-- Remember to rename to .htaccess by removing the .txt extension when placing this in your ROOT.

A guide to the .htaccess file below with some pointers and configurations that might work for you, be sure to make a backup of your original file! While working on my SEO score I found numerous articles that cover the subject however with my previous article more information is needed. Before we start to ensure that if you make an edit to check with your hosts help files there are small variations per host this can lead to errors. I've added some snippets you will find handy to use, make sure to configure them according to your taste and test results.

Google PageSpeed Module.

The Google PageSpeed Module is a server-side open-source module that is used by most 3rd part hosting service like GoDaddy. And is enabled through your .htaccess file and improves the performance of JavaScript, HTML, CSS, and, JPG/PNG images. mod_PageSpeed as it is also known works on Pache and Nginx servers. For 3rd party, hosting check the provider hosting FAQ. For those who manage their web servers, Google offers a wide range of install packages.

Debian & Ubuntu.

sudo dpkg -i mod-pagespeed-*.deb
sudo apt-get -f install

CentOS & Fedora.

sudo yum install at# if you do not already have 'at' installed
sudo rpm -U mod-pagespeed-*.rpm

Packages.

Adding Google PageSpeed Module functionality to the .htaccess file.

Below are a copy and paste of the PageSpeed modules for this website. This main purpose here is to clean HTML and CSS as well as moving the CSS to the header for optimized loading. Important to note here that some hosting services you will need to add PageSpeed functions per line in your .htaccess file or they will not work properly.

#Redirect from old domain to new domain with full path and query string:Options +FollowSymLinksRewriteEngine OnRewriteRule ^(.*) http://www.newdomain.com%{REQUEST_URI} [R=302,NC]

#Redirect from old domain with subdirectory to new domain w/o subdirectory including full path and query string:Options +FollowSymLinksRewriteEngine OnRewriteCond %{REQUEST_URI} ^/subdirname/(.*)$RewriteRule ^(.*) http://www.katcode.com/%1 [R=302,NC]

#Rewrite and redirect URLs with query parameters (files placed in the root directory)

RewriteEngine onRewriteCond %{HTTP_HOST} ^example-old\.com$ [NC]RewriteRule ^(.*)$ http://www.example-new.com/$1 [R=301,L]If you do not want to pass the path in the request to the new domain, change the last row to: