How to Properly Implement a 301 Redirect
UPDATE: Refer to the comment section for even more geek speak and question-answering!
It’s time to put on our technical hats, boys and girls! The Wall Street Journal tried to instill some paranoia in newbie searchies by describing How Search-Engine Rules Cause Sites To Go Missing, inspiring visions of sites dropping out of the index at whim and costing site owners billions and billions of dollars in a single day. Oh, my!
The article uses Topix.net as an example, explaining that Rich Skrenta paid $1 million to acquire the .com TLD for the site and is now fearful that switching domains will cause Google to lose his site in the Web’s abyss. I don’t think Rich found Google’s response to his cry for help all too helpful either:
"…Google’s response to Topix’s plea for help was an email recommending that, if the switchover were to go badly, the company should post a message on an online user-support forum; a Google engineer might come alone to help out."
Heh, I can see why that would make him nervous, but I think Rich and Company are going to be okay. I’m not sure they need to spend $1 million to secure a new TLD in the first place, but what’s done is done. What’s left to do now is alert the search engines to the change.
But how do you do that? With a 301 redirect.
A 301 redirect is a command used to tell the search engines that a page has permanently moved, and that you want them to index the new page and drop the old one from their index. It’s basically a change of address card for the Web. As long as everything is done correctly, a 301 redirect will ensure that you keep the rankings earned by the old page and it will prevent the duplicate content nightmare that should arise if the engines were to index box version of your site.
How to Implement 301 Redirects Using .htaccess for Apache
Breathe easy; this is fairly simple.
Before you get yourself all excited about the fun you’re about to have, make sure you have access to your server, your Apache Configuration file, and that you can use your .htaccess files. The ability to use .htaccess files will reside in a command called “Allow Override” in the Apache Configuration file. If you do not have this access, you’ll have to first call your hosting company and get access.
Once you know that you have access to this file, your next step is to locate it. The .htaccess file is a control file that allows server configuration changes on a per-directory basis. It controls that directory and all of the sub-directories contained within. In most cases, this file will be placed in the root Web folder for your Web site. If there’s no .htaccess file present, create one.
To begin using the .htaccess file to redirect page(s) on your Web site, open up your FTP and login to your Web site.
Work your way into in the root Web folder in order to access your .htaccess file. This little gem is the file you’ll need to edit. (A little piece of advice: The dot in .htaccess makes it a hidden file, so make sure your FTP browser is enabled to view hidden files. Otherwise you’ll never find it and your IT guy will laugh at you when you ask him for help.)
When you start editing the file, use a UNIX style text editor, not Notepad. Typically, an HTML editor or code editor such as TextPad works just fine. To 301 redirect pages using the .htaccess file, you will add a line to the file that will tell the server what to do. You can do this a couple of ways:
RedirectPermanent /old-file.html http://www.domain.com/new-file.html
Redirect 301 /old-file.html http://www.domain.com/new-file.html
A redirection from one domain to another would be:
RedirectPermanent / http://www.new-domain.com/
Our IT department reminds me there are some key things worth mentioning here:
- The first section of the command tells the server what to do: RedirectPermanent or Redirect 301. Again, these commands are equivalent.
- The second is the relative path to the file that you want to redirect. This must be the relative path to the location of the .htaccess file (i.e. /old-file.html).
- The last section is the full path to the new file. This is a fully-qualified URL, meaning you need the http:// (http://www.domain.com/new-file.html).
Once you have inserted the commands to 301 redirect your pages, you need to make sure that there is a blank line at the end of the file. Your server will read the .htaccess file line by line, which means at some point you’ll need to throw them an "endline" character to let them know you’re finished. An easy way to do this is to put a blank line at the bottom of the file.
You can test that your redirect was done properly by heading over to your search bar, typing in your old domain name, and hitting search. If you’ve correctly implemented your 301 you’ll be immediately taken to the new location. If you haven’t, go play in traffic. You’re useless and should be ashamed of yourself. Zing!
How to do a 301 redirect using a Windows server
Okay, this is a bit trickier. First, navigate your way to the Internet Services Manager (Programs — Administrative Tools — Internet Services Manager). Once you’re there, select the site you’re redirecting from, and right click to open up the properties menu. This will open up the Context menu. (Sadly, there is no ‘viola’ once this happens.)
Inside the Context menu you’ll see the "Home Directory" tab, click on it and select “A redirection to a URL” from the radio buttons at the top. The default choice will be to select "A directory located on this computer" but that is NOT the option you want. Once you’ve made your selection, type in the new URL you want your old domain to point to. Make sure that the "A permanent redirection for this resource” is selected in the checkboxes underneath.
The other checkboxes listed handle some different options, depending on what you want to do:
If you need more options for what you’re redirecting to, you can add some control variables to the "Redirect to" box where you just entered in the new URL. The most useful variable for domain redirects is $V. This removes the server name from the original request.
For example, http://www.youroldsite/directory1/page1.html would redirect to http://www.yourNEWsite.com/directory1/page1.html. Leaving this control variable out will only redirect the home page. If other pages are ranked in your site, then it would be extremely helpful to redirect those pages using these variables also.
To finish, press "ok” and you’re done! Huzzah!
I Can’t Do Either of These, What Now?
Sigh. You’re sad, that’s what.
No, no, if you don’t have access to your .htaccess file or your Windows Server Administration Panel, you can still implement 301 redirects with code on your old pages, but you have to do with one hand tied behind your back and wearing an eye patch. Fine, no eye patch. If your pages are in PHP, ASP, Java, or any other language that allows you to modify Response Headers, simply place code at the top of each page to do the Permanent Redirect.