The Missing Guide: 301 Redirects
The modern web is fluid, with new pages being built and old ones being deleted on a constant basis. If you are planning to delete pages or reroute visitors from an old page or domain to a new one, this is the guide for you.
Why do I need a 301 Redirect?
301 redirects perform two major tasks: most importantly, they inform search engines that your page or site location has moved, and transfers the page rank and “link juice” from the old to the new. It’s a relatively simple solution to preserve a page or site’s hard-earned search rankings after it has moved. The second benefit is that every outstanding link or bookmark will still send visitors to the new site, so you don’t have to worry about broken links.
This is strictly a guide for an
.htaccess 301 Redirect, which is the most common server-side method. It is a requirement that your website be on an Apache server with
Mod Rewrite turned on; most hosting companies use this, but if you aren’t sure, check with your host.
First, you need to force your computer to recognize the
.htaccess file, the file we will be editing in later steps. By default, any files beginning with a “.” are hidden on most computers because they are usually sensitive operating-system files that would cause damage to the system if accidentally edited or deleted. However, we need to be able to see and edit a “.” file for our website, so here’s what you need to do:
1. Go to Applications>Utilities and open Terminal. With the window selected, paste the following and hit Enter.
defaults write com.apple.Finder AppleShowAllFiles TRUE
2. Force Finder to relaunch by pasting the following code and hitting Enter again.
3. When you are finished and want to hide system files again (which is generally a good idea), repeat the same steps, but replacing TRUE with FALSE.
defaults write com.apple.Finder AppleShowAllFiles FALSE
Then force Finder to relaunch again:
PC Users (Windows Vista & Windows 7)
1. Launch Windows Explorer.
2. In the Organize drop-down menu, choose Folder and Search Options.
3. Under the View tab, scroll down and check the box next to “Show hidden files and folders.”
4. To hide the files again, simply go back and uncheck the box.
Now that you can actually see the file you’ll working on, go to your site’s root directory, or topmost folder. There you should find the
.htaccess file. If you don’t have one, I’ll explain how to create one.
If There is No
Never fear, creating one will be a quick and painless:
1. Go to any basic text editor like Notepad or TextEdit, and open a new document.
2. In the first line, write the following:
3. Go ahead and Save As, and make sure the file name is simply
.htaccess, with no
.txt or anything after it. If you followed the step above to allow your computer to view hidden files, this should be no problem.
That’s it! You’re set up to begin the next steps.
If There is an
1. Download it and open it in a basic text editor like Notepad or Text Edit.
2. Ensure there is a line that reads:
If that line isn’t there, type it in on the first line. Make sure any code you add is below this line.
Adding the 301 Redirect
The next step is to add the code that will perform the redirect. While there are many types of redirect, we’re only going to look at redirecting single pages and domains. If you need a different type of redirect, a quick search should yield a snippet that you can paste in place of the below snippets.
Page to Page Redirect
To redirect from an old or deleted page on your domain to a new one, paste the following code into your
.htaccess file below the
Rewrite Engine on line, replacing the information to reflect your site and page names:
Redirect 301 /oldpage.html http://www.yoursite.com/newpage.html
That’s it! The old or deleted page is the first item, and the full address of the new page follows.
If you changed web addresses, you’ll need to direct search engines and traffic to the new one. In this case, you’ll need to start a new blank
.htaccess file and paste the following:
Options +FollowSymLinks RewriteEngine on RewriteRule (.*) http://www.newwebsite.com/$1 [R=301,L]
.htaccess file will be placed on your old domain, so this will only be effective as long as the old domain stays live. It’s suggested that you keep your old website live until search engines recognize the 301 and credit the new page with rankings. For more information on helping Google recognize your new site, I recommend this article on how to properly move domains from an SEO standpoint. In the meantime, it’s important that you contact any site or directory containing backlinks to ensure they have the new URL for your site.
Uploading and Testing
Good news—you’re almost there! Your last step is to upload the new
.htaccess file to your website’s root directory. Once that is done, be sure to test and make sure the old address redirects you to the new page or domain!
Congratulations—you’re now a 301 veteran.