Web Analytics

The 301 Redirect: What it Does and Why it Matters

by Jason Unger, Founder
301 Redirect

I was watching The Social Network recently (it’s a great movie, but that’s another blog post unto itself), and this line by Erica Albright, Mark Zuckerberg’s girlfriend (who may or may not actually be real), stuck with me.

The Internet’s not written in pencil, Mark, it’s written in ink.

There’s so much truth in this. For as editable as the Internet is — from changing content on Wikipedia to publishing and removing tweets to adding and deleting pages on your website — once something exists online, there’s always going to be a trace of it.

Politicians and celebrities are constantly getting busted for tweeting something stupid or controversial, and journalists almost immediately take screenshots before the tweets are deleted. Archive.org and Google cache websites in their index, and even if you’ll rarely get the “full experience” of the site again, much of it is still accessible long after it is deleted.

So when something goes up on the Internet, rarely can it ever be completely removed.

As your website evolves (which it should always be doing), you’re going to be adding and removing content and pages constantly. You may even convert from one content management system to another. Usually, that means the URLs of your pages change — which can throw a wrench into the permanency of your site.

It may not seem like a big deal when your URLs change, but it is: there’s a lot of people counting on your URLs staying the same forever. Consider this:

  • Google knows the URL of your page. If you change it, Google is sending traffic to a dead page.
  • Any social media shares associated with that URL become useless when the URL changes.
  • Folks who use bookmarks in their browser (yes, they still exist) will have non-working links when the URLs change.

Your URLs are written in ink. But what happens if you have to change them, for one reason or another?

Enter the 301 redirect.

The 301 Redirect Points to the Right Direction

Let’s say that you’re moving into a content management system for the first time.

For example, if the pages on your site are:

  • /about.html
  • /services.html
  • /contact.html

Moving into a content management system may change the URL slug (the part of the URL after your domain name) to:

  • /about-us
  • /our-services
  • /contact

If you want to ensure that people who try to access /about.html are redirected to your new about page at /about-us, you need to set up a 301 redirect.

In its simplest form, a 301 redirect tells a web browser that anyone attempting to access a specific URL should be permanently redirected to a new URL you set.

For the user, this is a seamless transition; they don’t need to know that they’re being redirected – they simply end up on the correct page.

Setting up 301 Redirects

On a typical Apache server, 301 redirects are created in the .htaccess file.

A .htaccess (hypertext access) file is a directory-level configuration file supported by several web servers, used for configuration of site-access issues, such as URL redirection, URL shortening, Access-security control (for different webpages and files), and more.

WordPress automatically creates the .htaccess file for its URL structure settings, but you can always create one using FTP. The .htaccess file is nothing more than a blank file that goes in the root folder of your site.

In that .htaccess file, you can add all of your redirect rules, including your 301 redirects.

The simplest 301 redirect looks like this:

redirect 301 /about.html http://www.example.com/about-us

You can do this over and over for as many specific pages you want to redirect … and you should. To be clear, if you’re changing your URLs, you need a redirect for each page that has a name change. I’ll let Google explain just how important this is:

If you need to change the URL of a page as it is shown in search engine results, we recommend that you use a server-side 301 redirect. This is the best way to ensure that users and search engines are directed to the correct page. The 301 status code means that a page has permanently moved to a new location.

We’ve done this over time as we’ve added and removed pages to our site, and most recently, when we changed domains, we needed to redirect all traffic from www.jungermedia.com to www.digital.ink. Here’s the code we used to do that:

RewriteEngine on
RewriteCond %{HTTP_HOST} ^jungermedia.com [NC,OR]
RewriteCond %{HTTP_HOST} ^www.jungermedia.com [NC]
RewriteRule ^(.*)$ https://www.digital.ink/$1?di=jm [L,R=301,NC]

Basically, this tells any browser that traffic to jungermedia.com (or www.jungermedia.com) should be redirected to dgtlnk.com, and that any additional slug (shown in this case by the $1) should be appended to the URL. We also add in a little code to display an announcement bar so that folks expecting to see Junger Media know that we changed our name to Digital Ink.

Variations on the 301 Redirect

There are a ton of different ways to implement the 301 redirect. In addition to the two cases shown above, heres’s a few other examples.

Redirect to the www version of a domain

This pushes anyone visiting example.com to www.example.com.

RewriteEngine on
RewriteCond %{HTTP_HOST} ^example.com [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301,NC]

Use the alternate for redirecting to the non-www version.

RewriteEngine on
RewriteCond %{HTTP_HOST} ^www.example.com [NC]
RewriteRule ^(.*)$ http://example.com/$1 [L,R=301,NC]

Redirect one directory to another

If your directory names have changed, use this.

RedirectMatch 301 ^/olddirectory/$1 http://www.example.com/newdirectory/$1

Redirect a whole site to one URL

If you have consolidated pages and want to make sure every old page redirects to one new page on your site, use this

RewriteEngine On
RewriteCond %{HTTP_HOST} ^example.com$
RewriteRule ^$ http://example.com/pagename/ [L,R=301]

Even Though It’s in Ink, You Can Still Edit It

Not surprisingly, there are a number of WordPress plugins that can manage your redirects for you. We recommend Redirection (though be sure to turn off logging if you expect a ton of traffic to your redirects).

With the way that sites change over time, it’s not unusual to have dozens (if not hundreds) of 301 redirects in your htaccess file. It’s the one place that keeps a record of how your site used to be, in order to keep it inline with how your site currently is.

So while we can make sure the ink we use continues to say what we want it to say, unfortunately, there’s nothing we can do for Mark Zuckerberg’s real (or dramatized) past life. Somehow, I think he’s doing OK, though.

Avatar photo
About Jason Unger

Jason Unger is the Founder of Digital Ink. He built his first website on Geocities, and hasn't looked back since. Digital Ink tells stories for forward-thinking businesses, mission-driven organizations, and marketing and technology agencies in need of a creative and digital partner.

Other Stories You May Like

What’s your story?

Let’s share it with the world.

Let’s Do This

Close Window
All the Cool Kids are Doing it

Sign Up for the Digital Ink Newsletter

All the cool kids are doing it.