March 30, 2010

SEO Basics: How to safely redesign or move your website with .htaccess

Some day you’re going to want to redesign or move your website and, if you don’t know anything about how SEO works, wipe out all of your search engine traffic. Follow this guide to keep all of your traffic.

Step 1: Check your URLs

If you redesign or move your website hosting but keep the same URLs for every page, you have nothing to worry about besides the normal SEO concerns every page has.

A URL (Uniform Resource Locator) is the address of a web page on the web. The URL for this web page, which you can see in your web browser’s address bar above, is:

http://www.joshklein.net/seo-basics-how-to-safely-move-redesign-your-website

If this URL were to change by moving to another domain name, changing the name of the article in the URL, or adding something to the address (like “/articles/“), it would lose its search engine traffic.

And if this page were to be deleted, traffic would encounter an error page and would quickly disappear as well.

Step 2: What are 301 Redirects?

You’ve established that your URLs are changing. Now, it’s time to redirect the search engines to find your page at its new URL.

“301″ is a server’s HTTP status code given in response to a web browser’s query that says, in effect, “this document has been permanently moved.” This is the status you want your old documents to have when human visitors or search engine spiders come to your website.

If you leave your old pages up, they will return a “200″ status code which means “this document is OK, we have it right here, check it out.” The search engine will send search traffic to this page instead of your new page, and when you change the links of your website the old page will slowly lose its search traffic.

Also, because search engines try to keep duplicate content out of their indexes, your new page may not even be indexed while this old page responds with a 200 status.

If you just delete your old pages, they will return a “404″ status code which means “this document does not exist.” The search engines will assume the page is gone (it is gone) and remove it from the search index. Then you’re starting over from scratch.

Step 3: Setting up 301 Redirects with .htaccess

Status codes are responses in the HTTP header of your page, before any HTML is returned, which means that you need access to changing these headers.

If you use a CMS (content management system) and have no file directory access to your website, you might have to use some plugin for your CMS. Look in your CMS’s help section or contact their support team.

If you do have direct access to your website’s file directory, the best way to perform a redirect is with a directory level configuration file called “.htaccess”. Note that the file technically has no name; the “htaccess” is the file’s extension. On most systems (like Windows and OS X), files beginning with a “.” are considered hidden files and will not be observable in your file explorer or finder unless you turn hidden files on through your system configuration. However, that’s unnecessary for what we’re doing today.

Create a file called htaccess.txt with a plain text file editor. Open that file and add the following line:

Redirect /full/path/to/oldpage.html http://www.example.com/newpage.html

Replace “/full/path/to/oldpage.html” with the full server path of the file you are redirecting, and everything following that with the full URL of its new home.

Next, upload htaccess.txt to the old website’s root directory. Finally, rename the file to “.htaccess” and you’re off to the races.

Test that the redirect is working by visiting your old page – it should automatically forward you to the new URL.

Step 4: Update your XML sitemap and contact linking sites

As a final step, make sure you update your XML sitemap with your new URL structure and submit it to the search engines.

Additionally, although new linking sites will link directly to your new pages, any existing links will be linked to the old URLs. You can leave these 301 redirects for eternity, but after a few years or additional redesigns, you may forget to maintain the redirects. It would be preferable to contact the administrators of sites linking to you and have them update their links.

Step 5: Bonus tricks

Redirect entire domain to a new one:
Redirect 301 / http://www.example.com/

Redirect visitors to use “www” prefix:
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.example\.com$ [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301]

Redirect visitors to use secure “https://” prefix:
RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://www.example.com/$1 [R,L]

Step 6: Other ways to redirect

Step 7: Technical Resources

---