Boost Your SEO With .htaccess

seo with htaccess

For those of you utilizing an apache server and not taking advantage of your .htaccess file you are definitely missing out! This one file can make or break large news sites, expensive content marketing efforts, and even small business sites so today I'm going to break down the basics of how to use it. These simple tactics can ensure you avoid the angry wrath of panda, help your user experience, and overall search engine rankings. 

 

 

*WARNING please back up your .htaccess file before trying to modify it, you'll thank me later!

301 Redirect With .htaccess

Ever move a page, change a url, or switch domains? Of course you have and this is why you need to know how to utilize a 301 redirect to prevent loss of authority, traffic, link juice and several other factors. While many of the popular content management systems out there have modules or plugins that will write your .htaccess file for redirects here is the quick, easy, and fool proof way to do an .htaccess 301 redirect. In addition to the redirects make sure to tell Google via webmaster tools that your site has moved.

 
Redirect 301 / http://www.yournewdomain.com/
 
This will redirect your entire current site to the new domain, although this works fine we recommend doing page to page redirects  in addition to the entire domain redirect like the one found below.
 
Redirect 301 /page.html http://www.yournewdomain.com/page.html
 
You would use this for important pages such as an infographic or a resource page that is moved from one domain to another but the content remains almost the same. This will speed up the process of Google's indexing of your new domain.
 

Redirect Non www to www and Vice Versa with .htaccess (Fix Duplicate Content)

Whether your new to SEO or you've been doing it forever there is one thing you should know and it's that duplicate content should be avoided at all costs! When your site will resolve when you go to either  www.yoursite.com or just yoursite.com this is viewed as duplicate content. You can prevent this with a couple of lines in your .htaccess file.

Options +FollowSymLinks 
RewriteEngine on 
RewriteCond %{HTTP_HOST} ^yourdomain.com [NC] 
RewriteRule ^(.*)$ http://www.yourdomain.com/$1 [L,R=301]
This makes sure  yourdomain.com redirects to www.yourdomain.com
 
Now say you have a very branded domain and you don't want people to be distracted by www.  you can do the same type of redirect that will take www.yourdomain.com and redirect it to yourdomain.com see below.
 
Options +FollowSymLinks 
RewriteEngine on
RewriteCond %{HTTP_HOST} .
RewriteCond %{HTTP_HOST} !^yourdomain\.com
RewriteRule (.*) http://yourdomain.com/$1 [R=301,L]
 
Both of these methods work fine as a far as SEO and search engines are concerned.
 

Remove index.php or index.html From Displaying With .htaccess (Fix Duplicate Content)

Whenever your site resolves to www.yourdomain.com and www.yourdomain.com/index.php this is viewed as duplicate content and can split your link juice if some people link to just your domain and others with the index.php at the end. See the fix below:

RewriteEngine on
# index.php to /
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /.*index\.php\ HTTP/
RewriteRule ^(.*)index\.php$ /$1 [R=301,L]

Create a 404 redirect with .htaccess

Why would you want to create a 404 page you say? Well simply put the internet is constantly evolving growing and changing, pages get moved links get taken down etc. You need a solution for when your content goes missing or just plain isn't working. This will both provide a better user experience as well as prevent duplicate content(using catch all to redirect to home page).

ErrorDocument 404 /404-page.html

This will redirect any broken links or moved pages to your custom made 404 page and give a response of 404 to search engines. It is best practice to place an html sitemap on this page so that users can navigate back to a page similiar to what they are looking for instead of bouncing.

 

These topics just scrape the surface of htaccess seo send us an e-mail, tweet us, or send a facebook message for more help with .htaccess!