MoreNiche Affiliate SEO Tutorials
Basic htaccess Guide; Redirects and Beyond
This two part guide looks at the manipulation of the .htaccess file. It is one of the most versitle files on your site and can help you with SEO as well as site security and more.
Remember you can get access to more great articles and expert webmaster help by becoming an affiliate with MoreNiche today. Build your own site and earn fantastic commissions by referring sales to our specially chosen merchants.
Join MoreNiche Now!
In the first part of the guide we will examine what the .htaccess file actually is and how to do simple SEO friendly redirects.
There are lots of onsite factors that effect SEO, more in-fact than some people care to admit. One of these factors is effectively managing redirects on your site. In this guide we will look at how the .htaccess file can help you control redirects on Linux based servers.
Microsoft servers have their own special IIS commands and options that you will have to manipulate separately. Plug-ins are available to encourage .htaccess compatibility but you will need to install them and be aware of limitations.
What is .htaccess?
The .htaccess is a simple text based document that controls lots of different server commands and modules. It is placed inside directories of your site and works on a hierocracy, a page will always use the closest .htaccess to determine what it should be doing.
To create a .htaccess file simply use notepad and use the File>Save As command to make the file into .htaccess.
Some operating systems do not allow you to name something nothing.htaccess so you may need to call it something like temp.htaccess and simply delete the “temp” part once you have uploaded the file.
One thing to be aware of, some CMS have their own .htaccess file, make sure you do not overwrite it and delete all the formatting that it has placed. Wordpress is especially bad for this as it often locks and hides the .htaccess file. If you find uploading a .htaccess document breaks your sites links then simply go into the Wordpress settings and update your permalink structure.
The Basic Commands
There are a few basic commands for your .htaccess that will help with SEO. They are listed below with explanations. You can see that some lines ave “##” beside them, these are simply labels inside there .htaccess document and much like comments in HTML.
The parts highlighted in bold are usually the parts you will have to customise.
Enable Rewrite
##Rewrite Engine on Code##
Options +FollowSymLinks
RewriteEngine on
This code turns on the technology you need make the redirects work, you must put it before your other commands. If you find some redirects are not working try putting it before all commands but most servers do not require this step.
Redirect non-www. to www.
##Redirect non-www to the www version##
RewriteCond %{HTTP_HOST} ^example.com [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301]
This code redirects your websites root address from http://www.example.com to http://www.example.com. Double indexing and therefore duplicate content issues can cause problems on your site so this code will make sure visitors who arrive at http://example.com get forwarded to the full URL.
Make sure you edit the bits in bold to reflect your domains.
Redirect Index Page to Root
##Redirect index to root##
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /.*index\.html\ HTTP/
RewriteRule ^(.*)index\.html$ /$1 [R=301,L]
This solves another common duplicate indexing problem caused by spiders indexing root and your index page as separate things even though they are the same (content wise).
Make sure you edit the bolded parts to reflect the file type your site sues, for example if you use a PHP site change the html parts to PHP. In the unlikely even that index is not your index page you would need to change this too.
Note: In some situations, especially with advanced CMS this code can cause minor issues. If you find the code is stopping you log in simply remove it but I have never actually seen this happen.
Error Handling
##Error Handling##
ErrorDocument 401 /401.html
ErrorDocument 403 /403.html
ErrorDocument 404 /404.html
ErrorDocument 400 /400.html
These codes will allow you to use custom error pages, there are positive and negative SEO conditions around this but I believe it more beneficial for users to give them a custom error page so if you can be bothered to create them you can redirect them with this. Remember to edit the URLs to point to the page or pages you have created.
In this instance you must use a path pointing ot a page relative to the root. Do not type the full domain out as this will cause the page to send 200 status not an error.
SEO Friendly Redirect
##Standard 301 Redirect##
redirect 301 /old-page.html http://www.example.com/newpage.html
This is the basic code needed to redirect a page on your site to another page on your site.
It’s really useful if you move a page and have links and SEO juice you don’t want to lose. It’s also useful during site redesigns or when you buy a previously used site and need to change pages.
The format for a redirect is pretty simple.
Redirect {code} {/old-page} {full URL of new page}
Make sure you include one space between each part and that the old URL is in relative terms and the new one is a full URL including the http part. If your URL is in a subdirectory simply include it in the path.
##Standard 301 Redirect including Subdirectory##
redirect 301 /articles/old-page.html http://www.example.com/newpage.html
A few words of caution…
The 301 is a permanent redirect and search engines will gradually update their records with the new URL so make sure you are sure you want to redirect before doing it.
Simply change the number at the start to 302 should you wish to temporarily move a page.
Make sure you remove any redirected URLs from your sitemap as Google will generate errors for your sitemap if you leave them in.
Make sure you don’t loop redirects, very bad things can happen if you are sending visitors in an infinite loop, at the very least your site will generate a 500 server side error.
Make sure you are not redirecting the same page twice.
Keep one redirect per line, it’s easy to manage and see.
In the next part of the guide we will look at some more advanced features, I strongly recommend you get used to using the basic commands first but if you feel ready we can continue to part two.
Advanced Use of .htaccess
You can also download a template .htaccess filto save you copy and pasting so much. It's insde the zip file below.
Example .htaccess File
Do you want to get more from your affiliate marketing?
Do you want more great tutorials like this one that will guide you down the path to ebing a super affiliate?
If "Yes" then sign up for FREE today by clicking the link below.
Join MoreNiche Today