webserver

How do I set up a 301 redirect in Apache?

An Apache 301 redirect is typically set up so you can safely redirect website traffic from your old pages to the new pages without losing your page rankings.

What is 301 redirect?

A 301 redirect is the best method to preserve your current
search engine rankings when redirecting web pages or a web
site. The code “301” is defined as “moved permanently”.
After the code, the URL of the missing or renamed page is
noted, followed by a space, then followed by the new
location or file name. You can implement the 301 redirect by
creating a .htaccess file or updating the httpd.conf.

What is a .htaccess file?

When a visitor/spider requests a web page, your web server
checks for a .htaccess file. The .htaccess file contains
specific instructions for certain requests, including
security, redirection issues and how to handle certain
errors.

How to implement the 301 Redirect

1. To create a .htaccess file, type vi .htaccess from your DocumentRoot.
2. If you already have a .htaccess file, you can vi it and start editing.
3. Place this code in your .htaccess file:
RewriteEngine on
RewriteRule ^/path/to/old.html /path/to/new.html [L,R=301]
4. If the .htaccess file already has lines of code in it, skip a line, then add the above code.
5. Save the .htaccess file
6. You can test it by typing in the old address to the page you’ve changed. You should be immediately taken to the new location.

Notes: Don’t add “http://www” to the first part of the
statement – place the path from the top level of your site
to the page. When the search engines crawl your site again they will
follow the rule you have created in your .htaccess file.
The search engine doesn’t actually read the
.htaccess file, but recognizes the response from the
server as valid.

During the next update, the old file name and path will be
dropped and replaced with the new one. Sometimes you may
see alternating old/new file names during the transition
period, plus some fluctuations in rankings. According to
Google it will take 6-8 weeks to see the changes reflected
on your pages.

If you have direct access to your server’s Apache configs, you can update the httpd.conf instead of the .htaccess. You would use the same format as what was used in the .htaccess file:

RewriteEngine on
RewriteRule ^/path/to/old.html /path/to/new.html [L,R=301]

2 Comments

2 Comments

  1. Sylvie Porst

    July 27, 2010 at 11:15 pm

    Awesome post!

Leave a Reply

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

To Top