In this lesson we look at how to move your pages with 301 redirects.
Imagine you've got a page on your website that has attracted a whole lot of good links, and is attracting a lot of traffic, but you need to move it to a different place on your website. You probably don't want to outright delete the page and simply recreate it somewhere else - you'll lose all those great links and all that PageRank as well.
The solution is the 301 Redirect. This takes all traffic and links arriving at your old page and redirects them to the new page; your links are safe, your PageRank is safe and your visitors still get to where they need to be.
301 Redirects can be created in several ways; the preferred method is by using your .htaccess file (if you're using an Apache server, which you probably will be)
First, make sure you've created your new page!
Then open (or create, if it doesn't exist) the .htaccess file in the same directory as your page, and paste the following code:
Redirect 301 /my-page.php http://www.example.com/new-page.php
Save this, upload, and your redirect should be in place! Easy as that! This method is the most powerful because you can redirect entire folders/directories, or even entire websites with it, e.g.
Redirect 301 /current-directory http://www.example.com/new-directory
If you're not sure how to edit your .htaccess file there is an alternative method: using a PHP file.
Move or delete your old page (e.g. rename 'my-page.php' to 'my-page-old.php'), create a new page with the same name (i.e. create a new page called 'my-page.php') and paste in the following code:
<?php Header( "HTTP/1.1 301 Moved Permanently" ); Header( "Location: http://www.example.com/new-page.php" ); ?>
When you save the page, you have to save it as a .php page. You also need to be sure that there's no .html version of the same page in the same place, because the web server may use the .html version instead of this one.
Once you've got all that, upload the page, and the redirect should start working immediately!
Note that this method is only good for redirecting one page, and only works on php pages. (If you need to redirect multiple pages you must replace each page you want to redirect)
In this lesson we looked at ways to redirect your page without losing all of its links or PageRank. The two methods we looked at were: