How to Properly Implement a 301 Redirect

What is 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.

Think of it as 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 prevent duplicate content that could arise if the engines were to index both versions of your site.

How to Implement 301 Redirects Using .htaccess for Apache

Make sure you have access to your server and 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 config 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 subdirectories contained within. In most cases, this file will be placed in the root web folder for your site. If there’s no .htaccess file present, create one.

To begin using the .htaccess file to redirect page(s) on your site, open up your FTP and log in to your site. Work your way into in the root web folder in order to access your .htaccess file.

(Note: The dot in .htaccess makes it a hidden file, so make sure your FTP browser is enabled to view hidden files.)

When you start editing the file, use a UNIX style text editor rather than 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 tells the server what to do.

To 301 Redirect a Page:

RedirectPermanent /old-file.html http://www.domain.com/new-file.html

To 301 Redirect an Entire Domain:

RedirectPermanent / http://www.new-domain.com/

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 it an “endline” character to signify that you’re finished. An easy way to do this is to put a blank line at the bottom of the file.

How to Do a 301 Redirect Using IIS on a Microsoft Windows Server

Navigate your way to Internet Information Services (IIS) Manager, which is found with Administrative Tools within the Start menu. From there, you will find a panel on the left-hand side that lists all your sites. Choose the site you want to work on.

Once you select it, several modules come up. Verify the URL Rewrite module is present. If it is not, you can install it here.

Once you have it, double-click to open the module. On the right-hand side, you will see an option to Add Rules. Click it and then select Blank Rule under the Inbound Rules section. Hit OK. This will take you to an Edit Inbound Rule page. Type a name for the rule, such as Old Domain Redirect or Old Page Redirect.

Go to the Match URL Panel. Set the requested URL at “Matches the Pattern” and then Using as Regular Expressions. Now you will specify if you’re redirecting a single page, a group of pages, or an entire domain:

  • To redirect a single page, type in the page name under Pattern. For example, if we were redirecting this blog post, we would input blog/how-to-properly-implement-a-301-redirect/ in the Pattern field.
  • To redirect the entire site, we would input (.*) in the Pattern field.
  • To redirect all the pages on BruceClay.com within the SEO folder, we would input seo/(.*)

Make sure “ignore case” is checked.

Skip down to the action panel and select Redirect within the Action Type drop-down menu. In the Action Properties, type in the new URL. If it’s a single page, input the single page. If it’s the entire domain or a group of pages, type the new destination with a back reference, which is {R:0}. The back reference will keep all page URLs intact with the new domain.

For example, if we were changing BruceClay.com to BCI.com, we would input http://www.bci.com/{R:0}

If you use tracking parameters and you want them to carry through, check Append Query String.

In the Redirect type field, select Permanent (301).

Click Apply at the top right in the Actions column to save the redirect.

(If you want to review the redirect, hit back to rules in the Actions column.)

After you save this redirect, the rules you created are saved into the web.config file, which you can edit in the future.

Alternative Methods to Implement a 301 Redirect

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. 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.

Why You Might Need to Implement a 301 Redirect

There are many times a 301 redirect makes sense. Here are a few of the most common:

  • You’re changing your entire root domain.
  • You want to reorganize pages by changing or removing a directory.
  • Let’s say CNN posted a link to this blog post, but the URL was incorrect. We’d still want to capture the traffic that is going to a 404 page. So we’d put in a 301 redirect to direct users from the bad link to the right URL.
  • You want a vanity URL.