« Local Search Inclusion | Home | Pay-Per-Call »
How to 301 redirect
By John Rodriguez | November 27, 2007
What is a .htaccess file?
When a visitor/spider requests a web page via any means, 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.
What is a 301 redirect?
The code “301″ is interpreted 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
How do I implement a 301 redirect?
First of all, you’ll need to download the .htaccess file in the root directory of where all your web pages are stored. If there is no .htaccess file there, you can create one with Notepad or a similar application. Make sure when you name the file that you remember to put the “.” at the beginning of the file name. This file has no tail extension.
If there is a .htaccess file already in existence with lines of code present, be very careful not to change any existing line unless you are familiar with the functions of the file.
Scroll down past all the existing code, leave a line space, then create a new line that follows this example:
redirect 301 /old/old.htm http://www.you.com/new.htm
It’s as easy as that. Save the file, upload it back into your web and test it out by typing in the old address to the page you’ve changed. You should be instantly and seamlessly transported to the new location.
Notes: Be sure not to add “http://www” to the first part of the statement - just put the path from the top level of your site to the page. Also ensure that you leave a single space between these elements:
redirect 301 (the instruction that the page has moved)
/old/old.htm (the original folder path and file name)
http://www.you.com/new.htm? (new path and file name)
A more powerful set of directives for manipulating URLs is contained in the Apache mod_rewrite module,? especially useful when changing domain names and/or folder names containing large numbers of files.
Redirecting entire sites with 301
The 301 directive is quite powerful. You can redirect not just single files but entire sites, for example when changing domain names e.g.
redirect 301 / http://www.you.com/
The first “/” indicates that everything from the top level of the site down should be redirected.?As long as you are using the same paths and filenames, then this option is a very simple way to perform site redirection in the situation where you have only changed your domain name.
If the site redirection doesn’t work for you, check to ensure you have the trailing “/” on the destination URL. You may also like to try some of the other suggestions in our basic tutorial on the apache mod_rewrite module.
Canonical issues: www vs. non-www
There’s been much talk lately of canonical issues and search engines. This is where both the www and non-www versions of your pages are listed in a search engine. This is said to possibly trigger a duplicate content penalty and/or split page rank. If this is of concern to you, you may wish to use the following, but be aware that you may suffer a further loss of traffic while the engines sort out what’s what. This example is where you wish to direct all non-www traffic to www. Add the following to your .htaccess file.
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^yoursite.com [NC]
RewriteRule ^(.*)$ http://www.yoursite.com/$1 [L,R=301]
Ensure that all your links to folders always end in a trailing / if there is no filename after that link.
FrontPage users:? in addition to the above, you’ll also need to change the .htaccess files in:??
_vti_bin
_vti_bin /_vti_adm
_vti_bin/ _vti_aut
Replace “Options None” to “Options +FollowSymLinks”?
Those folders are part of your FrontPage extensions on the server, so you’ll need to gain access via FTP.
Note: test, test and test again after making changes. Test *immediately* after implementing 301 redirects. If you find anything wrong, remove the redirect immediately. User a server header checker to ensure that you’re getting a correct 301 response when using the old URL.
Topics: Web Design |
Comments
« Local Search Inclusion | Home | Pay-Per-Call »


