.htaccess is a configuration file for use on web servers running Apache software. Usually all public hosting providers use Apache.
You can take advantage of .htaccess by creating or changing this file in your “public_html” directory.
Optimizing 404 errors with .htaccess
Websites tend to lose content or change urls from time to time. Not working urls stays in google cache and when google bot crawls them they receive 404 not found error instead of 200 ok. It is better to avoid giving google and most of all your visitors, broken links.
For example we recently removed “http://www.cheapseoservices.org/directory-submission-service/” from our website, but google has it listed and people may find it with keywords like: “cheap directory submission service”, so it is more convenient for the visitor if we redirect him to related or current services we are offering.
We add this line to our .htaccess file:
ErrorDocument 404 /404.php
and create 404.php file in “public_html”
404.php:
This will redirect all our 404 not found pages to homepage, where user will be able to see what we currently offer. Google also sees this as a benefit, because we are making sure visitor is not left alone and he gets at least related information he was looking for.
Enabling Gzip compression
Gzip compression is a feature nowadays websites and browsers use to improve website load time. One of google ranking factors is page speed, so if you can, use this method. Most modern hosting providers have mod_gzip module running on their Apache.
To enable gzip compression add this code to your .htaccess file:
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.*
Forcing www.
Technically urls “www.website.com” and “website.com” are duplicates and sometimes if you enter website url without “www.” you get an error.
To avoid errors and inconvenience for the user, choose if you want to use www. or not and add this code to your .htaccess file:
301 Redirect (redirect non-www to www): RewriteEngine On RewriteBase / RewriteCond %{HTTP_HOST} ^cheapseoservices.org [NC] RewriteRule ^(.*)$ http://www.cheapseoservices.org/$1 [L,R=301]301 Redirect (redirect www to non-www): RewriteEngine On RewriteBase / RewriteCond %{HTTP_HOST} ^www.cheapseoservices.org [NC] RewriteRule ^(.*)$ http://cheapseoservices.org/$1 [L,R=301]
Creating SEO friendly URLS
Instead of having urls like: ”www.mywebsite.com/index.php?page=contacts&id=9999″ it is better to use seo friendly urls like: “www.mywebsite.com/contacts/”. SEO friendly urls are more convenient for the user, because he can easily indentify what is the website about, just by looking at the address bar.
To create SEO friendly urls add this code to your .htaccess files:
RewriteEngine on RewriteRule ^/ index.php RewriteRule ^portfolio/ index2.php?page=portfolio
301 permanently moved redirect for moved content
Sometimes you have to change location of your content. For example www.cheapseoservices.org/some-topic/ has to be changed to www.cheapseoservices.org/some-topic-and-additional-features/. To avoid serving your visitors page not found errors, use this kind of code in your .htaccess file:
Redirect 301 /oldpage.html http://www.cheapseoservices.org/newpage.html









Leave a Reply