Get Free Quote
« Can Google Clean Up... | Blog home | Calling It Linkbait... »
March 13, 2007

How to Properly Implement a 301 Redirect

Print Friendly

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

-or-

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:

  • “The exact URL entered above”:

This will redirect the search spiders and users to the exact URL you entered in the “Redirect To:” box. For instance, if you somebody went to http://www.youroldsite.com/products/index.html, they would go to http://www.yournewsite.com/.

  • “A directory below this one”: Freaky Friday images aside, this redirects a parent directory to a child directory. For instance, if someone typed in http://www.yoursite.com to access the site and you wanted the request to be redirected to a child directory named “tools”, then they would be sent to http://www.yoursite.com/tools.

 

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.





32 responses to “How to Properly Implement a 301 Redirect”

  1. Hawaii SEO writes:

    Great post!

    So… Why does Google use a 302 redirect to go from: google.com – to – http://www.google.com?
    Why doesn’t Google use a 301?

    What if you want to redirect internal pages with a 301?

    http://www.oldurldotcom/oldpage.asp – to – http://www.newurldotcom/newpage.asp (Easy enough)

    But… What if there are several variations of the old URL caused by the URL prefix?

    www & http:// & http://www & https:// – https://www – Would that require more than one redirect?

    What sort of redirect should you use if you have a new content management system and need to go from something like: http://www.coca-coladotcom – to – http://www.coca-coladotcom/index-d.html

    Should you use the robots.txt file to Disallow the URL with the extra characters via? http://www.coca-coladotcom/robots.txt

    Aloha,
    Dave.

  2. Lisa writes:

    Woah, Dave. Easy with the geek speak! You’ll hurt a girl with all those slashes, brackets and fancy words! I’m not going to lie, most of these questions were completely over my pretty little head, so I trotted myself down to our IT department, locked my favorite geek in a room, and fired them at him. Here’s what he had to say:

    1. My guess is that they don’t have a problem with both of them being indexed in Google, thus creating duplicate content. I think when you are the search engine, you probably aren’t violating any guidelines.

    2. If you are using Apache, then you can modify the .htaccess file on the site with the OLD URL to say:

    RedirectPermanent /oldpage.asp http://www.newurl.com/newpage.asp

    If you are using Windows Server, then you can browse to the file in the IIS Panel, right-click and hit properties. Instead of looking for the “Home Directory” tab, look for the “File” tab, and you can select the permanent redirection there.

    Or, if you don’t have access to these things, you can place this ASP code at the VERY TOP of oldpage.asp:

    3. Yes…kind of. If they are all redirecting to the same place, then the redirects above should work. If you want to redirect each one to a different place, it would be best to do a Mod Rewrite in Apache in order to 301 redirect them.

    In IIS, it is MUCH harder where you would need to have different sites defined for www. and non-www. in your panel and redirect those. For IIS, it would be much faster, simpler, easier, etc. to put ASP code on the pages or use an ISAPI Rewrite Module to redirect each different variation to a different location.

    4. Don’t use a redirect.
    Instead, make index-d.html your default page that loads when http://www.coca-cola.com is requested. To do this in Apache, add this line to your
    .htaccess:

    DirectoryIndex index-d.html index.html index.htm

    This defines index-d.html as being the first page that the server looks for on a directory request. If it can’t find that page, then it will go to index.html and so on.

    On a Windows Server, go to IIS, right-click on the web site or the directory and click Properties. Once there, click on the “Documents” tab. Then make sure that “Enable Default Document” is checked and add your new filename into the list. Then, move the new document name to the top of the list.

    5. I’m not sure what you’re asking here. If you don’t want a file to be indexed, then yes, use the robots.txt file to exclude it.

  3. Hawaii SEO writes:

    Thanks for the detailed & thoughtful answers.

    Aloha,
    Dave.

  4. Erik writes:

    Thanks for the great article.
    What if you’ve got to two servers on the same shared hosting?
    e.g.
    http://www.oldSite.com
    http://www.newSite.com
    and you want to
    a)redirect non-www domain of the new domain to its ‘www’ counterpart (e.g. newSite.com -> http://www.newSite.com)
    b)and redirect any requests to the http://www.oldSite.com domain to http://www.newSite.com
    ???
    Is this possible even though both sites are working off of the same .htaccess file (because of the shared hosting situation)?
    Can I modify each “.htm” file of the old site to point to its new counterpart (e.g. http://www.oldSite.com/page.htm -> http://www.newSite.com/page.htm) even though they are HTML files and not in PHP, ASP or Java?

  5. Erik writes:

    Nevermind, I’ve figured it out. I wrote a series of four conditionals in the .htaccess file that redirect appropriately based on what URL is requested.

    Basically it just redirects all pages on the old domain to the new one AND redirects ‘non-www’ URLs to their ‘www’ counterparts.

    I’ll put up my code for anyone to be able to dissect and use based on their requirements.

    Options +FollowSymlinks
    RewriteEngine on
    rewritecond %{http_host} ^newSite.com [nc]
    rewriterule ^(.*)$ http://www.newSite.com/$1 [r=301,nc]

    rewritecond %{http_host} ^oldSite.com [nc]
    rewriterule ^(.*)$ http://www.newSite.com/$1 [r=301,nc]

    rewritecond %{http_host} ^www.oldSite.com [nc]
    rewriterule ^(.*)$ http://www.newSite.com/$1 [r=301,nc]

    rewritecond %{http_host} ^oldSite.com/ [nc]
    rewriterule ^(.*)$ http://www.newSite.com/$1 [r=301,nc]

    rewritecond %{http_host} ^www.oldSite.com/ [nc]
    rewriterule ^(.*)$ http://www.newSite.com/$1 [r=301,nc]

    *Note: the “/” behind any domain name on a condition line takes whatever page off of the domain name in the URL was requested and sends it to the page of the same filename on the new domain (I the “$1″ variable asks the server to retain the filename from the request).

  6. Samantha writes:

    ok, so let’s say you’re in the unfortunate situation where you’re unable to do either. you’re unable do htaccess or a 301 through windows server and you have to edit each page by hand.
    what would you do to change the response code and then add it to the header? what would that code look like? is there an example for that?
    i know i could google it, but i have done that before and the results that i found didn’t work correctly.
    -thanks!

  7. Sandip writes:

    Thanks for the post. Is there any suggestion on how to handle a situation where a URL needs to be redirected to an “SEO friendly” one. TLD remains the same.

    e.g:
    Old URL: http://www.site.com/20/30/1123.html
    corresponding new URL: http://www.site.com/coats/furcoats/longfurcoat.html

    I would assume in the absence of 301 redirects, there will be 2 differently formatted URLs indexed and it’s unclear what the impact on the page rankings will be

    Thanks.

  8. Vijay Teach Me writes:

    Thx Bruce,
    For last couple of days I was having difficulty for 301 Redirect code.
    You gave many examples and thx to all those made comments.
    Vijay

  9. James writes:

    Samantha, if you can’t use htaccess and do a 301 redirect, then you could do a meta-refresh as long as the time period is under 1 second. However, can someone please verify that the meta-refresh counts as 301 and not a 302 redirect.

    Thanks
    James

  10. Ranjana writes:

    Hi,
    It counts as a 302 redirect.
    With a 200 OK on both the start and target page, the search engine index both the start page and the target page.
    Since this method is a known spam method, it is best to avoid it.
    Regards
    Ranjana

  11. tyler dewitt writes:

    Bruce clay: I did a 301 redirect, but I’m having some major issues. I was in the top 5 for website design and great traffic, I did the 301 about 1 week ago and now our traffic has dropped and no calls from google for like 1 week now. which I just did the 301 redirect 1 week ago

    now my keyword is in positions 500-600 was number 4, how long does it take things to level out and get my traffic and rankings back? My headers tags are reading 301 and I implemented it correctly?

  12. Allison writes:

    A couple questions:
    1) I’ve heard about software that is coming out that allows you to implement an .htaccess file on an IIS server. Does anyone have more info on this or know where I could learn more about this?
    2) You mention the following, “The ability to use .htaccess files will reside in a command called “Allow Override” in the Apache Configuration file.” How do I find the Apache Configuration file? Is it typically named the same thing and found in the root, or elsewhere? Can I find it if I have FTP access? And if I have my FTP client setup to view hidden files and I don’t see an .htaccess, is it always safe to upload one? I have a client who is on an Apache server, but I don’t see an .htaccess file. However, the site redirects to the home page if there is a 404 error. I thought the only way to do this on Apache was in the .htaccess but I can’t find the file. Is there something I’m missing?
    Thanks!

  13. John Sisler writes:

    Hi Allison, I am not aware of an .htaccess file for use on an IIS server but there are native functions in IIS to do everything you need to do.

    If you are running an apache server and you do not have access to the .htaccess file there is another method to redirect which is to code the redirect in the pages. The limitations are scalability for a large site but if you cannot manage it at the server level you may have to consider doing it at the file level.

    There is a pretty compreshensive page on doing this with different scripts (java, vb, php) at http://www.somacon.com/p145.php

  14. derek writes:

    Hi maybe you can help
    About 3 days ago i done a 301 direct from my old domain to new domain.
    Both sites are now indexed with google for the same key phrases, how long before the old domain goes from index. or will they punish me for dup content.
    Thanks

  15. Aaron writes:

    I am trying to get a nonwww to www redirect when people come to my site. How do I correctly get the ISS redirect to work. I went into ISS, followed ALL instructions and it still wont redirect my site to www if someone enters it without www. ANy ideas?

  16. clenbuterol writes:

    The limitations are scalability for a large site but if you cannot manage it at the server level you may have to consider doing it at the file level.

  17. Prechha Narongthai writes:

    I am not aware of an .htaccess file for use on an IIS server but there are native functions in IIS to do everything you need to do.

  18. Jim Glockner writes:

    We are incorporating a 301 redirect in our dev/uat environment before we move this to production as a proof of concept. This environment is not accessible via the DMZ therefore I cannot test accuracy to ensure the 301 header is displaying correctly via the many tests that are offered out there by inserting the domain into a textbox and returning a "http / https Header Check". Are there any ways I can test this internally?
    Can you pls respond.
    Thank you
    Jim Glockner
    Webmaster Deluxe Corporation
    webmaster@deluxe.com
    jim.glockner@deluxe.com

  19. Trade show displays writes:

    Great article! What if i don’t have IIS admin access and only using .htm pages?

    what should i do?

  20. Dream writes:

    I wanna know if you had an opinion on what I should do about the permanent redirect for an ASP Site . I cannot do it with my index page having an html extension. Should I change my homepage to extension .asp? That’s the only way I think I can do it.

  21. Starr McCaffery writes:

    Wow, this is the most informative article and string of comments I’ve found in about 3 weeks of searching. I have an old site created by someone else that I am taking down but want to do a basic/minimal hosting to redirect the domain (which I own) and pages to the new site. Old site has .asp pages. New site used a site builder that won’t allow me the various folders, sub-folders and long page name structure of old site. I understand how to redirect the old pages to the new corresponding but slightly mis-matched page names with an asp redirect. My problem is I don’t have IIS access and don’t know how to redirect the domain itself (there are links out there that I’m trying to change over but that takes time) without IIS access. My instruction on asp redirect says insert code and save as oldpagename.asp. But my domain isn’t a page name. Any advice? First I tried to set up hosing for the old domain on Linux and do .htaccess and that works for the domain, but with the asp pages it doesn’t so I need to switch it to Windows. Is there a Windows-compatible file, like an .htaccess, that I can use for the domain? Thank you.

  22. Webkinz writes:

    If I want to redirect a one domain to another, is there a difference between a 301 redirect and a permanent redirect? or are they the same thing?

  23. Greyer writes:

    I have some problems with the 301 redirect. I need to redirect /index.php?/archives/old-url.html to /archives/new-url.html. I tried with Redirect 301 /index.php?/archives/old-url.html /archives/new-url.html but for soem reason it didn’t work :( any suggestions?

  24. SEO Mumbai writes:

    It’s great that you have touched upon a subject that is rarely discussed about. 404 errors are one of the worst impediments to your search engine rankings and are not taken well by SEs. You need to have a proper 301 redirect procedure in place, especially if you constantly add and remove pages to your website.

  25. John Weidner writes:

    If you ever have trouble trying to do a redirect and set a cookie as part of the same response, if your using IIS 5.0, the problem might be caused by an IIS bug.

    http://support.microsoft.com/default.aspx?scid=KB;en-us;q176113

    It seems as if IIS filters out the cookies. If you are trying to redirect to an application server, you might try redirecting directly instead of going through the web server.

  26. ecommerce web development writes:

    Thanks for the clarification on this issue. It seems to be something that isn’t going to go away and we need to make sure we address it.

  27. USA Magazines writes:

    Awesome easy guide ! A newbie can understand that very well .Thanks for the post !

  28. Free Games writes:

    Great guide, really good described. I have just implemented it on my site which runs on apache box and it worked. better safe than sorry and not get kicked out because of dublicate content :)

  29. microsoft points free writes:

    It’s fantastic that have referred to a topic that rarely discusses. 404 errors are one of the worst obstacles to their search engine rankings and are not taken well by the SE. You need to have a proper 301 redirect procedure in place, especially if you constantly add and remove pages from your website.

  30. Club Penguin Cheats writes:

    the .htaccess file always gives me fits. This helps. Although I usually have help with stuff like this. But I think with this guide I can now do it myself!

  31. Chris schwarz writes:

    Hi,

    I am bringing in in a new website and plan on setting up 301 redirects in the .htaccess file.

    Do I need to keep the OLD .html pages on the server?

  32. Susan Esparza writes:

    @Chris – There’s no reason to keep the pages on the server once you’ve put in a redirect. However, it’s always smart to keep a backup of your pages somewhere. You never know when you’ll need that information again.



Learn SEO
Content Marketing Book
Free Executives Guide To SEO
By continuing to use the site, you agree to the use of cookies. AcceptDo Not Accept
css.php