Wednesday, February 16, 2011

How to Redirect a Website or Web Page and Preserve Its Rankings

by Herman Drost

Need to redirect your old website to a new one? Need to redirect an old page to a new page? Want to transfer the rankings of your old site to your new one? Want to redirect non www pages to www pages?

These are a few of the questions website owners ask when they redesign their websites and want to preserve their rankings. For instance you have a static html site that's been redesigned into a Content Management System (CMS) such as WordPress and want to make sure visitors accessing the old pages in the search engines get redirected to the new pages

What is a 301 redirect?

When search engines index your web pages they store them in cache memory (data that is repeatedly required). When you change the URL of your web page or website it still remains in Google's cache. This means people searching for your site will still see your old website. To prevent this from happening you need to redirect your old web pages to the pages on your new website. This is a achieved through a 301 redirect sometimes called 301 permanent redirect.

Requirements

Filezilla (FTP software) This is free FTP software you need to transfer files from your desktop to the server. To transfer the files you simply drag files from your local (computer) window to the remote (server) window.

Apache web server 99% of web servers these days use Apache to host websites however check with your web host before implementing a 301 redirect. It won't work on a Windows server.

.htaccess file This is the text file containing your 301 redirect code which is uploaded to the root directory of the server (same location as your index.html file). If the .htaccess file is already on the server download it to your desktop then open it with Wordpad or a text editor. Avoid using MS Word...it will mess up the code.

301 redirect code This is the code to add to your .htacess file to redirect your site or pages to your new site.

Procedure

*Create a .htacess file in a text editor and save it as .htaccess.txt

*Add the 301 redirect code and save the file

*Upload the .htaccess file to the root of the server of your old site

*Test the redirect works by entering the old URL in your browser It should automatically redirect to the your new website

Sidebar: If you're redirecting non www pages to www pages upload the .htaccess to the root of the server files of your current website.

Examples

1. To 301 redirect your old website to your new website use this code:

redirect 301 / http://www.example.com/

Replace example.com with the URL of your new site. This will redirect traffic from your old site to the index page of your new site. Keep in mind it won't redirect each page to it's new page.

2. To 301 redirect a single page use this code:

redirect 301 /oldpage.html http://www.example.com/newpage.html

Replace oldpage.html with the URL of your old page and replace newpage.html with the new page you want to redirect to.

3. To 301 redirect a folder to another folder use this code:

redirect 301 /folder/ http://www.mysite.com/folder/

Multiple folders (subdirectories)

redirect 301 /subdirectory/subdirectory/ http://www.mysite.com/subdirectory/subdirectory/

Keep this code all on one line in your .htaccess file.

4. To 301 redirect non www pages to www pages use this code:

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

Replace mysite with your own website URL. Test if the redirect works by entering mysite.com, http://mysite.com in your browser. It should redirect all pages to the www version.

5. To premanently redirect an old domain to new domain use this code:

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

Replace newdomain.com with the URL of your new domain.

6. To redirect .htm pages to .php pages use this code:

RewriteEngine on RewriteBase / RewriteRule (.*).htm$/$1.php

Make sure you have mod_rewrite enabled on your server.

7. To redirect any index.html pages to your home page use this code:

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

You will have multiple home pages if your navigation menu contains mutiple index.html pages. This confuses the search engines because they'll be dividing your traffic between 2 types of home pages e.g. index.html and http://www.yourdomain.com. Use the code above to redirect all index.html pages to the home page. Replace index.html with index.php if your site contains php pages.

Test your 301 redirect works

Type the URL of your old website into your browser address bar. it should immediately redirect to the new website. Also check that your non www pages redirect to www pages. Use this 301 redirect checker to make sure your redirects were sucessful.

http://www.ragepank.com/redirect-check/

Tips

When redirecting the files of an old domain or website to a new domain or new website maintain the registration and hosting account of the old domain. This gives search engines time to index and update the backlinks of your new site. Terminate your old website only when there are no traces of it in the search engines. This will take a few weeks or months.

Notify your link partners of the domain name change as soon as possible. After you terminate your old domain any search engine benefits you've built up through your old links will be gone unless you've implemented the 301 redirect. When obtaining new backlinks make sure they point to your new domain.

Create a 404 error page in case you used the incorrect code in your .htaccess file.

Read "How to Create a Custom 404 Error Page to Stop Losing Visitors" http://www.drostdesigns.com/how-to-create-a-custom-404-error-page/

Avoid using 301 redirects to redirect multiple domain names to your main website. Search engines will rank websites if they are a good resource for their visitors.