301 Redirect and .htaccess Tips

A friend of mine who is just starting out (Internet business) was asking me the other day about 301 redirects, www’s vs non-www’s in domain and the .htaccess file and how it all relates to what I do and SEO etc.  Because of that, I wanted to post it here on this blog.  I have posted this information in other places before, but wanted it here for any of the Dream Systems Media readers to have access to it.

For anyone who is serious about search engine optimization knowing about 301 redirects is a MUST.  I searched and searched all over for the “bottom line-tell me how to do it” examples of the 301 redirects and found the information confusing.

What you need to know, and NOTHING more!

First: The code to get your non www’s always redirecting to the www’s is as follows:

Here’s the code:

RewriteEngine On
RewriteCond %{HTTP_HOST} ^yourdomain.com
RewriteRule (.*) http://www.yourdomain.com/$1 [R=301,L]

(Make sure your Apache installation has mod_rewrite enabled.)

As long as your Apache installation has mod_rewrite enabled then you should be able to use this fix on almost any host.

Second: If you have any old page urls that are being replaced by new search engine friendly ones, but do not want to lose your page rank then here’s the code for that:

redirect 301 /old/oldurl.html http://www.newurl/new.html

MAKE SURE you DO NOT include the http://www.whatever.com  ONLY USE whats after the .com starting with the / or it will not work!  Also make sure to only put ONE space in between everything!

There you go!  That is as simple as it gets…or at least as I can make it!

Remember why we do the 301 redirect:

Mainly for Google.  Google does not like a bunch of error pages and if you have alot of 404 error pages that do not exist anymore (maybe after doing a redesign, or introducing new SEF naming conventions) then its harder for Google to crawl and you can lose the page rank the page has.  With the 301 redirects you do not lose PR and you will not have to worry about duplicate content issues with your www and non www’s.  That alone is worth doing it!

A side note it might be a great idea to have your web designer create a custom 404 error page so it directs people to something useful so you are not losing traffic just in case a page is forgotten in this process. I have found that people are more willing to give the site a second chance when they see a custom 404 error page that helps lead them to the place they might have been looking for!

14 thoughts on “301 Redirect and .htaccess Tips

  1. Pingback: The 5 Minute SEO Site Audit Checklist | Search Engine People | Toronto

  2. Pingback: SiteProNews: Webmaster News & Resources » Blog Archive » The 5 Minute SEO Site Audit Checklist

  3. Pingback: The 5 Minute SEO Site Audit Checklist | News | Adsense Money Making Blog For Advice On Racking In The Cash With Adsense

  4. Pingback: Web design, SEO Site Audit Checklist | Custom Website Design - Web Links Directory - Software Development

  5. James Williams says:

    Hi Mat,

    I have a question about 301 redirects I have used on my site with the help of a plugin. I have made them no-follow but I am unsure if I am doing the wrong thing. I would really appreciate your advice.

    I have ‘Debt Guides’ on the index bar with a list of the guides, all the sub-domains, listed as 301 redirects.

    In my Google Webmaster tools, it shows as ‘warnings’. Should I remove these 301 pages?

    I am not looking for a link, but I am looking for your advice, so if you would prefer to email me direct and not post my comment that’s ok with me.

    James

    James Williams’s last blog post..A Debt Management Plan Can Help You Get Out Of Debt

  6. Dave Perris says:

    Hi Mat,

    Thanks for that info.

    Have been meaning to do a couple of redirects for a while. This is the first straightforward explanation I’ve found.

    I have one question, is the order of the code on the htaccess file important? For example I have a few IP addresses from habitual spammers blocked on my file. I’m going to redirect my non www’s and put in a couple of redirects, should they go at the beginning of the file or doesn’t it matter?

    Dave.

  7. Pingback: The 5 Minute SEO Site Audit Checklist | SEO Review

  8. Pingback: The 5 Minute SEO Site Audit Checklist | Search Engine Optimization Tips

  9. Spammy Name says:

    You helped me a lot with the 301 redirect code, Mat. I used it in my .htaccess file and it works like a charm.

  10. Eric Sterling says:

    good advice on the 404 pages. I use a free plugin that does something interesting. It provides a list of posts that the user might have been looking for, based on the keywords in the URL. It’s not too pretty, but it tries to be helpful.

Leave a Reply to Eric Sterling Cancel reply

Your email address will not be published. Required fields are marked *