301 Redirect

Rating: 1 - I can do better 2 - Jury's out 3 - Pretty darn good 4 - Splendiferous 5 - Awesometastic (by 0 people)   Your rating: 1 - I can do better 2 - Jury's out 3 - Pretty darn good 4 - Splendiferous 5 - Awesometastic

301 Redirect

Use this quick tutorial to do a 301 redirect, and pass on page rank & search engine position status from one page to another. 301 redirects can be tricky - use this guide for help!

Bookmark and Share

Why Use A 301 Redirect? 

If you're changing the actual URL structure of a page on your site (for instance, mysite.com/cars123.html to mysite.com/cars456.html), and the original URL has page rank, a prominent position in search engine results and/or backlinks - you'll want to pass on its stature to the new page. The best way to do it is with a 301 redirect!

301 redirects are helpful because they're search engine friendly and the ultimate way to pass on credit from an old page to a new one. Even if you're looking to delete a page - use a 301 redirect to forward it to your home page, or the parent page it was under, so that any old hyperlinks out there won't point to a 404 - Not Found page. Don't worry about redirections - once you've added the 301 redirect statement, search engines will do the rest!

About This Tutorial 

The 301 Redirects being covered in this tutorial are strictly for .htaccess file redirects, with the usage of the Apache web server with the function Mod Rewrite turned on. An .htaccess file is the configuration file of Apache, which lets you set configuration settings that search engine spiders obey. This is the most common redirect setup. To get started, find the .htaccess file in your website's root directory, save it to your desktop, and open it with Wordpad or your favorite text editor.

You'll see 301 Redirect code snippets in this tutorial - you can simply copy and paste them into your .htaccess file, and edit "mysite.com" with your site name.

A Single "Page A to Page B" 301 Redirect 

If you want to redirect "mysite.com/old.html" to "mysite.com/new.html", add the following line to your .htaccess file, under the line "RewriteEngine on":

Redirect 301 /old.html http://www.mysite.com/new.html

The first URL is the one being directed, and the second URL is the one it is being redirected to. Note how you must not type out the full web address for the first URL!

301 Redirect a non-www Domain to a www Domain 

An important step for all webmasters is to redirect the non-www version of their URL to their www version (i.e., mysite.com to www.mysite.com) - otherwise, two versions of the site will exist, resulting in inaccurate analytical results, backlinks, and other issues. To fix it, look for the "RewriteEngine On" line in your .htaccess file, skip down two lines, and add:

RewriteCond %{http_host} ^mysite.com [NC]
RewriteRule ^(.*)$ http://www.mysite.com/$1 [R=301,NC]


(...of course, replacing "mysite.com" with your actual site name)

301 Redirect a Folder to a New Location, But Leave its Contents In-Tact 

Let's say you have an entire folder filled with sub-pages on your site, http://www.mysite.com/cars, and you've either renamed the URL structure of that folder to "/newcars" or wish to move it to "/newcars" (so that it looks like http://www.mysite.com/newcars). You'd also want all pages within the folder to remain the same, but just be located in the new folder named "/newcars" - so, the HTML page "cars/toyota.html" will still exist, but will just be located at "newcars/toyota.html". This is the statement you'd put in your .htaccess file, under the line "RewriteEngine on":

redirect 301 /cars/ http://www.mysite.com/newcars/

If you have a 2nd, 3rd, 4th, etc. level folder, like http://www.mysite.com/cars/classic and want to move "/cars/classic" over to "/cars/all/classic": http://www.mysite.com/cars/all/classic, you'd use this:

redirect 301 /cars/classic/ http://www.mysite.com/cars/all/classic/

* Note that when you redirect folders, always leave the trailing "/" after the folder names.

301 Redirect an Entire Folder & All of its Contents 

Unlike the previous lesson, let's say that I have a folder on my site, "/cars" (http://www.mysite.com/cars) and I'm getting rid of that entire folder and all of the pages within it, such as /cars/ford.html, /cars/toyota.html, /cars/acura.html and several dozen others. Since I no longer will be using those HTML pages, I'll want all of those pages, and the page for /cars itself, to point to http://www.mysite.com/products. This is what would be used:

redirectMatch 301 ^/cars/ http://www.mysite.com/products/

Similarly, say that you want to redirect an entire folder and all of its contents to a single HTML page (or whatever other page, like PHP, ASPX, etc.). For example, I want to move the entire category http://www.mysite.com/cars and all of its individual pages over to the single page, http://www.mysite.com/things/stuff.html:

redirectMatch 301 ^/cars/ http://www.mysite.com/things/stuff.html

Premanently redirect a domain to a another domain 

Maybe someday you don't care for your domain name anymore, and have found something better...or, your company moved. To move all of the contents of one domain name to another, create a blank ".htaccess" file (open Wordpad and save the file as .htaccess), and copy and paste this, and only this, into that file (adding in your new domain name):

Options +FollowSymLinks
RewriteEngine on
RewriteRule (.*) http://www.new-domain.com/$1 [R=301,L]


Note that when you 301 redirect an old domain to a new one, you'll have to keep paying for the annual domain renewal and server account of the old domain name. It's a real pain - but once the 301 registers and all traces of backlinks to the old URL are nowhere to be seen, you can consider removing the old domain and its account. Do not remove the account if the old domain still gets direct type-in traffic, though.

The [NC] statement 

You may have noticed [NC] in the 301 Redirect statement for the above tutorial named "301 Redirect a non-www Domain to a www Domain": it simply tells your server that the value before it is not case sensitive, and ignores differences between capitalized and non-capitalized letters.

Beware of [L] 

Take a look at this 301 redirect statement:

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


Notice the "L" in the brackets, near the end? Note that the "L" represents "last line". So, anything after this statement will be ignored. That's not a problem if this statement actually IS the last line in your .htaccess - otherwise, leaving that "L" in there will create a whole bunch of problems! Some 301 redirect tutorials out there have left the "L" in the statement with no explanation of what it is - and it will drive you crazy if you use it incorrectly.

Verify that the 301 Redirect Worked! 

As previously stated, you can simply visited the page or site you've redirected, and see if it automatically forwards over to the new URL. If not, you may see an error message, or a generic page from your ISP.

To see which redirects were unsuccessful, you can use a free 301 redirect checker:

301 Redirect Tips, Tricks and Info 

  • 301 redirects are instant, because the .htaccess file is consulted before the page loads.
  • You won't need to do a 301 redirect to any pages that have no backlinks or type-in traffic. Simply rename the pages, and re-submit an XML sitemap to your Google Webmaster and Yahoo Explorer accounts.
  • When you've done a 301 redirect, check all pages involved: if you've redirected a main page, check both that page and several of its sub-pages to make sure they are behaving the way you've anticipated.
  • 301 redirects pass all page rank and SERPs (Search Engine Results Pages rankings). The passing of page rank from a 301'ed page to another may take approximately a month or two to display properly (or as long as one "Google PR update cycle").

301 Redirect Tutorial: Reader Feedback 

Thanks for visiting my tutorial - leave a comment if you'd like :)

Look who made this lens!

Pixelrage

Pixelrage A quick 301 redirect tutorial