How to redirect a web page, the smart way

The internet today is full of webmasters that are always updating, editing and even deleting web pages.

Lets say you are updating your website completely, changing the names of page's filenames (ex: file.html to file.php) and so on, this is great, you should stay updated! But what if you want to get rid of those old pages without having to worry about those who go to the old web page and see nothing? It doesnt end there either, other visitors do include major search engines such as MSN, Google and Yahoo! If people are finding your old pages when querying in these search engines, and they attempt to go to that page that has been deleted or moved, they will get a "404 File Not Found" Error! Now i know you dont want that, no webmaster wants that!

UPDATE: For those of you still confused on what web page redirection is, I have written a follow-up article titled Understanding Web Page Redirection, the smart way, to help answer some of the questions I most commonly get in the comments of this article.

The 301 Redirect

The best way to redirect those pages is by using something called a "301 Redirect". What this 301 redirect does, is it blatantly redirects to a different page when it is triggered, what makes the 301 redirect the best, is that not only does it accomplish your redirect, it does it safely, no having to worry about the search engines penalizing you for it! To be specific, the 301 redirect tells the browser, or in other cases, it tells the search engines "Hey this page has been moved, here is the correct URL!". Think of it as you getting mail that is not addressed to your name, possibly addressed to somebody who has lived there prior to yourself, what do you do? You tell the post man (or woman) "Hey they dont live here anymore, here is the correct address". It is the same concept guys, pretty simple if you asked me!

So lets get started. Below you will see several methods of using the 301 redirect, including the redirect in PHP, the redirect in ASP, the redirect in ASP .NET, the redirect in JSP (JAVA), the redirect in IIS, the redirect in ColdFusion, the redirect in CGI/PERL and finally the one I find most useful, the redirect using htaccess. Also showing other useful ways of using the 301 redirect with mod_rewrite!

HTML Redirection

How do you redirect using html you ask? Here is how: DONT!

Over the past 4-6 years, use of meta tag refresh redirection has been abused for uses in relation to SPAM. The result of this and other scenarios of mis-uses of it, is that when using it, that page WILL be de-indexed from every search engine.

NOTE: This also applies to javascript redirection. Search engines can easily detect javascript and meta tag redirection, so just dont do it, use the 301 redirect.

301 Redirect Using htaccess

Using htaccess to accomplish the 301 redirect is highly suggested due to it being fairly convenient to manage, rather than setting redirects on each individual page, you can simply add the redirect code to the .htaccess file.

Here is how to do it:

  1. Create a file on the root directory of your website, name it ".htaccess".
  2. Open the .htaccess file using notepad or what ever text editor that you prefer.
  3. Add this into the .htaccess file, save it and then upload it to your web server:
    CODE:
    1. Redirect 301 /old/old.html http://www.you.com/new.html

NOTE: Don't add "http://www" to the first part of the statement - place the path from the top level of your site to the page. Also ensure that you leave a single space between these elements:

redirect 301 (the instruction that the page has moved)
/old/old.html (the original folder path and file name)
http://www.you.com/new.html (new path and file name)

Also note that you are not required to redirect the page to another domain, an equally useful purpose for using the 301 redirect, is redirecting old pages to the new pages on the same domain, it all works the same way!

UPDATE: .htaccess Editor is a simple, yet useful resource for generating htaccess files.

301 Redirect Using Mod_Rewrite

Mod_Rewrite has got to be one of the most usefull modules a server can have in terms of SEO, it allows to organize the file structure of your web site in a dynamic yet simple fashion, in this example I show a useful method of 301 redirecting with mod_rewrite.

When somebody links to your website, sometimes they dont always link to you in the way that you want them to. If somebody links to www.yoursite.com and somebody else links to yoursite.com, Google will assign a separate pagerank for each of those. Yes, it is stupid but it is true, by inserting the below example into your .htaccess file, it will solve the problem by redirecting anything linking to yoursite.com to www.yoursite.com, also redirecting the pagerank, so no worries!

CODE:
  1. RewriteEngine On
  2. rewritecond %{http_host} ^yoursite.com
  3. rewriteRule ^(.*) http://www.yoursite.com/$1 [R=301,L]

301 Redirect Using IIS

  1. In internet services manager, right click on the file or folder you wish to redirect.
  2. Select the radio titled "a redirection to a URL".
  3. Enter the page that the page will be redirected to.
  4. Check "The exact url entered above" and the "A permanent redirection for this resource".
  5. Click on 'Apply'.

301 Redirect Using ColdFusion

As well as many server side scripting languages, using the 301 redirect in them is fairly simple.

Simply add this code to your ColdFusion page:

CODE:
  1. <cfheader statuscode="301" statustext="Moved permanently">
  2. <cfheader name="Location" value="http://www.new-url.com/">

301 Redirect Using PHP

Simply add this code to your page or script:

PHP:
  1. <?
  2. header( "HTTP/1.1 301 Moved Permanently" );
  3. header( "Status: 301 Moved Permanently" );
  4. header( "Location: http://www.new-url.com/" );
  5. exit(0); // This is Optional but suggested, to avoid any accidental output
  6. ?>

301 Redirect Using ASP

Simply add this code to your page or script:

ASP:
  1. <%@ Language=VBScript %>
  2. <%
  3. Response.Status="301 Moved Permanently"
  4. Response.AddHeader "Location", "http://www.new-url.com/"
  5. %>

301 Redirect Using ASP .NET

Simply add this code to your page or script:

ASP:
  1. <script runat="server">
  2. private void Page_Load(object sender, System.EventArgs e)
  3. {
  4. Response.Status = "301 Moved Permanently";
  5. Response.AddHeader("Location","http://www.new-url.com/");
  6. }
  7. </script>

301 Redirect Using JSP/JAVA

Simply add this code to your page or script:

JAVA:
  1. <%
  2. response.setStatus(301);
  3. response.setHeader( "Location", "http://www.new-url.com/" );
  4. response.setHeader( "Connection", "close" );
  5. %>

301 Redirect Using CGI/PERL

Simply add this code to your cgi/perl script:

PERL:
  1. $q = new CGI;
  2. print $q->redirect(" http://www.new-url.com/ ");

301 Redirect Using Ruby/Ruby on Rails

(Thanks to Codeninja) Simply add this code to your ruby/ruby on rails script:

RUBY:
  1. def old_action
  2. headers["Status"] = "301 Moved Permanently"
  3. redirect_to "http://www.mynewpageorsite.com/"
  4. end

Pleaee note that all of the snippets of code above are examples and I have tested each at some point. However, I am in no way responsible for any damage the code may cause, you use this code at your own risk.

383 Responses to “How to redirect a web page, the smart way”

  1. prahlad said,

    May 14, 2008 @ 5:40 am

    Dear

    Thanks for information but can you tell me where we use this code at our web page or server i mean site rote

  2. Rene said,

    May 13, 2008 @ 7:28 am

    Hey Steven,
    Thanks alot for your simple explaination. Much appreciated!

    Rene

  3. RotoNation said,

    May 12, 2008 @ 4:40 pm

    Thanks, worked like a charm!

  4. jonny said,

    May 9, 2008 @ 6:02 am

    Hi. Great article, simple and easy to understand.

    However what if you have multiple pages to redirect? Do you create a separate htaccess file for each one or do you just add more lines in the one file?

    Also once you have the htaccess in place can you then delete the original html (in my case) page?

  5. alex said,

    May 3, 2008 @ 2:31 pm

    Hi, very interesting article. I have one question on redirection.
    how can be done, if someone (in asp.net) type
    http://www.example.com/car
    and not
    http://www.example.com/car.aspx
    ???

    Can this be done somehow?
    if it was in php (i think) it wouldnt nesessary…

  6. Andrew said,

    April 30, 2008 @ 2:39 pm

    Man I learned the hard way with the HTML redirect. I’m now using the php method and was able to get back on the right track. Cheers!

  7. SEOGuru said,

    April 28, 2008 @ 6:55 am

    Guys,

    We are switching our website over from .html to .cfm after a major update.

    Unfortunately as we’re on a shared windows hosted server we have no access to the IIS settings. Is there anything we can do (bar move server) that will allow us to redirect these pages?

    Also how do we go about dealing with the .html pages that are not going to appear in the updated site. Is there some code we can introduce on the html files that tells the search engines that the page is no longer in use?

  8. Bill Rolfes said,

    April 22, 2008 @ 3:17 pm

    I just had a need to redirect an old web page that appeared on a Google search, and found your article on 301 redirect. Since I have just a single small site I’ve just used a simple web publishing program, and was not familiar with how to do a redirect.

    I came across the page you published couple of years ago; thanks for the information; it seems to work fine for me!

  9. metin said,

    April 20, 2008 @ 11:55 am

    What if I want only a certain page of my blog/website to direct to another website/page, but I want the end user not to see the redirected page, but still see my page’s hyperlink on the address bar? What’s the best method for that?

    Thanks!

  10. Pradeep said,

    April 19, 2008 @ 5:17 pm

    Hello ,
    Really nice post, i got the term what i was looking.

    Thanks a lot
    Pradeep Tiwari

  11. Tom Grimshaw said,

    April 18, 2008 @ 8:41 pm

    Steven, thanks very much for taking the time to write it all up! I went looking for why my html redirects were not working and you have provided a much better solution, cleaner, more elegant and recommended.

  12. Majesticskull said,

    April 17, 2008 @ 2:18 pm

    Very good! I use the first solution and works very well.
    Thanks!

  13. neo said,

    April 17, 2008 @ 1:36 pm

    want to redirect from old website to new one old websites are:

    http://arcadiazone.page.tl

    server is on http://www.own-free-website.com/login.php, using website templates, as i don’t have access to the header on my pages what is the best action to put redirect when new website is finished

  14. ltlucky said,

    April 16, 2008 @ 4:45 pm

    So I’m using Yahoo web hosting and they don’t permit use or modification of the .htaccess file.

    I just created a php version of my html site.

    I’m guessing that the correct answer is to cancel my yahoo hosting and go with another company that let’s me use .htaccess, right?

    Any other ideas?

  15. Krishnan said,

    April 15, 2008 @ 12:30 pm

    I have situation where I want the page to be redirected as follows

    user gives https://abc.efg.com/ he should goto https://xyz.com/index.html

    for any thing like https://abc.efg.com/XXXX should not be redirected.
    this is because my application does not have a home page, user always has to login through the xyz.com . once logged in user can come to my application.

    Please help

  16. Cat said,

    April 8, 2008 @ 7:37 pm

    Hi Steve, was talking to you earlier but we got cut off. :) I was wondering how I can redirect from http://www.mamatales.com/forums to http://mamatales.com/Joomla/index.php?option=com_fireboard&Itemid=79

    We tried the standard 301 redirect .htacess file it did not work, and you tried another one with me dont recall exactly what it was. But if you can email me back or I will try to catch you on chat.

    Thanks,
    Cat

  17. patrice said,

    April 8, 2008 @ 5:56 am

    A site I volunteer at was set up to be accessed as http://site.org and NOT as http://www.site.org. I’m looking to redirect people who log into our site using www to the ‘plainer’ URL, but have been unsuccessful with variations of the 301 directions here (which I have used with success on other sites when redirecting to another, entirely different, URL). Is what I want to do possible?

  18. Wayne Herbert said,

    April 7, 2008 @ 12:08 am

    Hello, great article, learned a lot. I originally set up http://www.myco.com. Later, I grabbed another domain http://www.mycompany.com. I created some content in http://www.mycompany.com/content and using the redirect facilities within my Linux hosting (a 301 redirect I now understand) I set up content.myco.com to redirect to http://www.mycompany.com/content and it works just fine, except:

    I would like to keep the URL that is displayed as content.myco.com. I read most pages of messages in this thread and have not found the answer. Is there a way to do this?

    Many thanks.

  19. Rob Meades said,

    April 6, 2008 @ 5:18 am

    S’OK, found out that Redirect doesn’t send on query strings, you have to use RewriteRule instead. Maybe worth adding this as a note (unless I’m wrong!).

    Rob

  20. Rob Meades said,

    April 5, 2008 @ 5:36 pm

    Very comprehensive advice indeed, very glad I found this.

    One question: I’ve tried using redirect on my local server (Apache 1.3) and it works successfully on a static page. However, if the redirection is to the server in my webcam and the requested URL is a CGI script that takes a parameter (”img/image.cgi?next_file=main_fs.htm”) then the page doesn’t form correctly. It looks as though the parameter is going missing. Is there something extra I need to do to get the parameters to go with the redirection?

    Rob

  21. Marshall said,

    April 3, 2008 @ 2:16 am

    Thanks! Not only does this make it easy to keep people from accessing files that you don’t want them to, but it also makes it possible to still have the files on the server for future access if necessary. This could be a life saver for many.

  22. Ellen said,

    April 2, 2008 @ 11:52 pm

    Excellent article. Found it searching for the redirect…much better way to do it.

  23. Marg said,

    March 31, 2008 @ 5:29 pm

    Just a quickie to say… Hey Thanks!!

  24. Eddie said,

    March 29, 2008 @ 10:23 am

    You Da Man Steve. Thanks for the invaluable insight. I have many times wondered how to do this and it was solved in just 5 minutes. You have my deep gratitude.

  25. Kevin said,

    March 22, 2008 @ 8:53 pm

    Thanks so much for including all of these examples, BTW.

  26. Kevin said,

    March 22, 2008 @ 8:48 pm

    Oops, I didn’t turn my angle brackets into entities! Here’s try #2:

    For anyone looking for ColdFusion redirection, it is done this way:
    <cflocation url=”myNewURL.cfm” statuscode=”301″ addtoken=”no”>

    The attribute “statuscode” is new with CF8. This tag actually allows any of the status codes to be used, but of course for permanent redirection you need 301.

    Here’s more info in the documentation:
    http://livedocs.adobe.com/coldfusion/8/htmldocs/

  27. Kevin said,

    March 22, 2008 @ 8:46 pm

    For anyone looking for ColdFusion redirection, it is done this way:

    The attribute “statuscode” is new with CF8. This tag actually allows any of the status codes to be used, but of course for permanent redirection you need 301.

    Here’s more info in the documentation:
    http://livedocs.adobe.com/coldfusion/8/htmldocs/

  28. Barry said,

    March 20, 2008 @ 11:20 am

    What if I want a redirect based on some condition?

  29. Links de websites utéis | Yeltsin Lima said,

    March 19, 2008 @ 9:22 pm

    […] Redirecionando páginas, da melhor forma […]

  30. 100+ Resources for Web Developers « Share4Vn.com Blog said,

    March 19, 2008 @ 6:04 am

    […] How to redirect a Web page the right way Don’t lose PageRank! Steven Hargrove gives you the code to redirect using htaccess, Mod_Rewrite, […]

  31. stone said,

    March 18, 2008 @ 5:30 pm

    what if if i want the old page to appear for some time ( lets say 15 seconds ) and then go to new location ???????

  32. Top 15 Resources for Web Developers « Digg Duhh said,

    March 16, 2008 @ 6:08 pm

    […] How to redirect a Web page the right way Don’t lose PageRank! Steven Hargrove gives you the code to redirect using htaccess, Mod_Rewrite, IIS, ColdFusion, ASP, Java, Perl, Ruby and PHP […]

  33. 100+ Resources for Web Developers « arcagility said,

    March 14, 2008 @ 11:42 am

    […] How to redirect a Web page the right way Don’t lose PageRank! Steven Hargrove gives you the code to redirect using htaccess, Mod_Rewrite, […]

  34. Steven Hargrove said,

    March 14, 2008 @ 12:14 am

    Stacy - Make sure you’re redirect is not set up to redirect to a page where the same redirect code will get triggered. This will cause an endless loop of redirecting, in effect causing an internal server error.

    In other words, A should redirect to B, if A redirects back to itself (A) - you will get an internal server error.

  35. Stacy said,

    March 13, 2008 @ 7:17 pm

    I’m having some major trouble doing this. The code is very simple and I feel like I’ve been up since last evening trying to figure out how to hold a spoon in my hand. Apparently, the htaccess file is not a problem since I’ve tried all the codes and they’re right. The redirection works to something like msn.com, but when I do it to my own site, there either is no response or I get an internal server error or that the redirection can never be completed.

    Where does one look once the htaccess file is of no help anymore?

  36. 100+ Resources for Web Developers | BlogWell said,

    March 4, 2008 @ 10:03 am

    […] How to redirect a Web page the right way Don’t lose PageRank! Steven Hargrove gives you the code to redirect using htaccess, Mod_Rewrite, […]

  37. How to redirect a web page, the smart way at Ehsan Mahpour’s Weblog said,

    March 3, 2008 @ 2:12 pm

    […] Anyways, whoever is interested to read it can go to his weblog and read it. Click here […]

  38. Steve said,

    February 29, 2008 @ 8:08 pm

    Great tips, thanks for the help.

    I’m just wondering if it’s possible to use mod_rewrite to redirect to a different domain.

    I need to move my site from a .com to a .net. All the url’s are identical apart from the TLD.

    For example, I need over 3000 pages to redirect from
    http://www.mysite.com/pagename.php
    to
    http://www.mysite.net/pagename.php

    Is this possible?

  39. How to redirect a web page, the smart way at Ehsan Mahpour’s Weblog said,

    February 29, 2008 @ 4:02 pm

    […] 301 Redirect Using htaccess […]

  40. ofisboy said,

    February 28, 2008 @ 12:15 pm

    Rob, check your configuration.php. Somewhere in there you will see a path to your site without the “www”. Just add the www to that path and your problem will be solved.

  41. Domain Squatters and Redirecting Links from a Blog | WebDiggin.com: An Adventure to Make Money Online said,

    February 23, 2008 @ 2:30 am

    […] Steven Hargrove has a website on some cool web stuff and Search Engine Optimization info. He says the following about using HTML and meta tags to redirect: HTML RedirectionHow do you redirect using html you ask? Here is how: DONT! […]

  42. Rob said,

    February 23, 2008 @ 12:06 am

    Hi,
    Im wondering the proper html code to add to my frontpage website that would redirect my http://vacationrentalexperience.com to http://www.vacationrentalexperience.com
    It seems that some of my changes i make to my web pages go to the http://vacationrentalexperience.com url instead of the http://www.vacationrentalexperience.com help!

  43. djhassoo said,

    February 20, 2008 @ 3:21 am

    oh God, atleast i got it after searching so long, Thanks for sharing Mod_rewrite redirection code.

    Nice Theme :)

  44. Paul said,

    February 15, 2008 @ 1:43 pm

    sorry to bother you. Many years ago, with the help of MS Frontpage I made a web site for a friends golf league. The home page is index.html and I guess geocities requires that. I need to redirect.
    > Can you help?

  45. Colorado Small Business Blogging » Blog Archive » Not Redirecting Your Web Pages is Just Plain Rude said,

    February 14, 2008 @ 8:14 pm

    […] Many Redirection Examples […]

  46. El guardián del faro said,

    February 11, 2008 @ 8:33 pm

    […] y como realizarlas, porque hay muchos que lo han hecho ya, y bien, entre ellos Presunto Culpable, Steven Hargrove (en inglés) y EmezetaBlog entre otros muchos. Yo quiero hablar de eso otro que no suelen explicar […]

  47. Riscrittura delle URL e caratteri speciali e accentati - URL rewriting | Andrea Vit 's blog said,

    February 6, 2008 @ 5:07 pm

    […] vantaggio della riscrittura delle URL è bene prevedere almeno nelle pagine di primo livello una redirezione 301 dalla URL codificata stile “Wordpress” alla URL codificata in […]

  48. SEO Friendly 301 Redirects | Yakiji said,

    February 4, 2008 @ 2:31 am

    […] How to redirect a web page, the smart way (Steven Hargrove) Posted in SEO Tips […]

  49. sj said,

    February 4, 2008 @ 12:40 am

    Steven,

    I’m having trouble with the 301 redirect on my web site. I’m trying to use it to redirect page names that are no longer current after I have updated/renovated my web site. I do use URL rewriting, and my developers are telling me this is my problem. Here is what happens:

    This redirect line:
    301 redirect /item_23.html http://www.mydomain.com/Item_Name
    yields this:
    http://www.mydomain.com/Item_Name?SpeakerName=/item_23.html
    instead of:
    http://www.mydomain.com/Item_Name

    Do you know why? Do you know how I can fix this? Thank you.

  50. Shawn said,

    February 4, 2008 @ 12:21 am

    Steven, I’ve just built a new site to replace my existing site — updated programming, new features, etc. — so pages have new names. Right now, I have the new site hosted on a temporary domain, on a new host. I’m ready to redirect my DNS to the new host and make the new site my “live” site, but I don’t want to do that until I have the 301 redirect issue settled. I tried using the .htaccess code above, but I got a server error.

    Both my sites are database-driven, product catalog-type sites, so I have about 300 pages to redirect. The old page name format is /item_123.html. The new page name format is /Item_Name. The domain will remain the same. I have URL rewriting on both sites, though, and my web developer is telling me this complicates the 301 redirect code. Can you offer me any advice? Here are the URL rewrite codes for each site, from the .htaccess files, in case you need them:

    old/current site:
    RewriteCond %{REQUEST_URI} !item.php4
    RewriteRule ^item_([0-9]+)\.html$ /item.php4?id=$1

    new site:
    RewriteRule (.*)\.htm$ page_info.php?pagelink=$1
    RewriteCond %{SCRIPT_FILENAME} !-f
    RewriteCond %{SCRIPT_FILENAME} !-d
    RewriteRule (.*) index.php?ItemName=$1 [QSA,L]

    I’m not a programmer, so I’m giving you the info I have. I’m trying to find out what the appropriate 301 redirect code would be so I can give it to my developers.

  51. Thinking of changing domain names? » 404 Group said,

    February 4, 2008 @ 12:10 am

    […] on, you will need to use different methods for setting up a proper 301 redirect. Here’s a comprehensive blog post, and another, and here’s a forum with great detailed discussion about […]

  52. matt said,

    February 1, 2008 @ 6:19 pm

    nice list for redirect, I paste this…

  53. LL said,

    February 1, 2008 @ 11:04 am

    Do you know of any issues with using a Domain service to forward and mask a site. I am having an issue with my forwarding not working in IE7 upon initializing the IE7 browser. Works fine in Firefox and Opera

    Or is it just best to do it yourself? Can you code a mask in your own code?

  54. paul said,

    January 31, 2008 @ 6:09 pm

    i want to forward http://www.mydomain.com to http://www.mydomain.com/newdirectory so i created the .htaccess file below:

    Redirect 301
    /index.php
    http://www.mydomain.com/newdirectory/index.php

    I uploaded it to the root directory along with an empty index.php but it didn’t work. Did I do something wrong?

  55. Bruce Rhodes said,

    January 29, 2008 @ 10:45 am

    Here’s a park/multi-domain name question….

    I have multi-domain names (safeguardselfstorage.com, …etc.) parked at safeguardit.com

    Is this a bad practice for SEO?

    Also I use the Google Maps API key has to be generated for each domain name that I have parked in order for the map to work…what a hassle…

    Is there a better way? Please advise QUICK! as you are able …thx!

    Cheers!

  56. Crockett said,

    January 28, 2008 @ 8:31 pm

    This is the most comprehensive, server-neutral answer I have found to date! Now I can enhance my CMS with a 301 option instead of just a fancy 404.

    Thanks, and rock on with your bad self,
    Crockett

  57. Preity said,

    January 24, 2008 @ 7:29 am

    Thanks for the info. Its really of gr8 help. I would be applying the method “301 Redirect Using htaccess”. My site http://www.hgtechsolutions.com is being redesigned from html to php. So the urls have been changed. Should i need to specify, for each url, a new url or have to copy this code only once? pls advice soon. its urgent! Means i have to write Redirect 301 /index.html http://www.hgtechsolutions.com/index.php … like this specifying for each page in .htaccess file?

  58. Marvin said,

    January 20, 2008 @ 12:38 pm

    Great information, very valuable and practical advice, especially for those looking for a major site revision - such a me for example. Getting it right the first time is really important.

  59. Ali Akbar Khan said,

    January 19, 2008 @ 12:25 pm

    Dear Steven,

    I am using a free hosting server for my articles site. its can not allowed .htaccess for redirection for pages. I am using Article MS Script for my site. Tell me how i can redirect all pages on their links through php script and where i post this code for redirect pages to exact page location, like http://www.articleszone.co.cc/submit/ link with Submit Article. I am a not familiar with coding.

    Thanks

  60. Malik said,

    January 18, 2008 @ 5:24 pm

    Great stuff thanks for this. I was going to do it the meta tag way and said let me do some research first.

    Thanks,

  61. Sridhar Katakam said,

    January 16, 2008 @ 1:25 am

    How do I redirect visits to all the pages of my website to a particular URL?

  62. Lisa said,

    January 14, 2008 @ 7:21 pm

    I just had this tech dude with Godaddy.com tell me about 301 Redirect in a 10 second sort of way.

    My question was for me to take a Flash movie they have available via their “Website Tonight” platform serve as my home page. And have this redirect to my own FTP pages.

    You see, they either offer FTP OR Website Tonight (with flash). One or the other.

    So his fix for this was: Use Website Tonight for your FLash and have it do a “301 Redirect”.

    Kind of a ‘Driveby’ “explanation”. So what is this guy saying?

  63. Blake Lewis said,

    January 14, 2008 @ 1:52 pm

    Great tutorial! Thanks for sharing!

  64. kris said,

    January 11, 2008 @ 12:43 pm

    Thanks for the info!
    I’m setting up a new website with a CMS.
    All products will be situated at another URL.
    Your info will help a lot.

    THX
    Kris

  65. zhakee said,

    January 11, 2008 @ 12:05 pm

    Your information is great, but I’m not sure how to go about doing the following:
    I have two mirror image sites at blogspot dot com and I would like to redirect folks who visit one site, to the other. Where exactly would I paste which code so people visiting the blog get redirected to the other, AND, how would I notify them to update their bookmarks?

    The blog allows access to the code, but where in the code does this message go? Or?

    Thanks so much.

  66. Chris Schaffer said,

    January 11, 2008 @ 10:11 am

    Pure awesome on the amount of information you have given on every way to perform a good redirect!

    I know I will be using this as a reference and recommending it to others.

  67. Revantine, The Life and Times » Blog Archive » www1 vm said,

    January 10, 2008 @ 6:19 pm

    […] I forwarded the old webmail address to the new webmail address. This is a great site for different 301 redirects http://www.stevenhargrove.com/redirect-web-pages/ […]

  68. Status code HTTP e SEO - qualche consiglio utile | Andrea Vit 's blog said,

    January 9, 2008 @ 5:42 pm

    […] come redirigere le richieste HTTP con i più diffusi linguaggi di programmazione e web server; […]

  69. Ryan B said,

    January 9, 2008 @ 4:07 pm

    Great help, thanks! Question though…what if I want any page from our old site to redirect to our new site… example. no matter what someone types in http://www.oldsite.com/page1 or http://www.oldsite.com/blahblah but I want it all re-directed to http://www.newsite.com. Is this possible? Thanks!

  70. Ryan said,

    January 8, 2008 @ 10:07 pm

    Wow, thanks for the great tips. This made my life much easier after upgrading my site.

  71. Stephen Bussard said,

    January 6, 2008 @ 8:13 pm

    This is a good article because it’s bite sized. It’s a good tip that I typically wouldn’t consider doing otherwise. It’s always good to encounter other professionals in web development in a world of drag and drop.

  72. John said,

    January 6, 2008 @ 4:51 pm

    What if I want to redirect to a subdomain?

    For example->
    subdomain.domain.com

    redirected to
    http://www.domain.com/example.html

  73. Karlo said,

    January 3, 2008 @ 12:49 pm

    Thank you so much! Very helpful information!

  74. SEO said,

    January 3, 2008 @ 3:42 am

    Nice contribution…Very useful information for those who want to redirect their web pages.

  75. Kumquat said,

    December 31, 2007 @ 6:55 am

    HI & Thanks…
    Here comes the dumb, sincere question…
    but…I need to redirect from an empty server root to a subdirectory in the same hosting that can handle numerous domains. We have several domains pointing to the same pages…which lead to a joint, small eShop, not surprisingly.
    Apache on Linux, commercial shared hosting that requires either the real pages or and htaccess file in the root
    Previously there were html pages in the root, but we built new pages in php and put them in a hosting directory called /new…coming off the hosting root, obviously
    Then we erased the html old (&ugly) pages.
    Problem is other domains also point to the /new hosting directory, so it is a BIG hassle

    Many thanks for the help, everybody!

  76. Liz said,

    December 24, 2007 @ 11:45 am

    Wow! Thanks so much for the info on redirecting. I really appreciate it. I used it to redirect from an old subdirectory to a new domain. Thanks!!

  77. Steven Hargrove said,

    December 21, 2007 @ 11:46 am

    bleed,

    Thank you very much for letting me know about this.

  78. bleed said,

    December 21, 2007 @ 5:16 am

    hi… you got spamlinks in your code (no longer) linking to our site (thats how i noticed), that you can only see if javascript is turned off. to get rid of them check your footer (there is probably an additional and unwanted wp-footer include, more info here: http://wordpress.org/support/topic/123108/page/2). btw. they come back if you do not update your wordpress installation.

  79. Dainų tekstai said,

    December 13, 2007 @ 4:46 am

    Thanks for it. Very useful. But there is any solution with PhP to leave previos url when page redirect to new page?

  80. Frank Seidan said,

    December 11, 2007 @ 10:46 am

    How can I do in VBScript from client side if first URL is not avaialble , go to 2nd URL or so on.

    Frank

  81. Kent Website Designer said,

    December 8, 2007 @ 11:01 pm

    Great Article,
    Now I really know all ways to redirect pages, especially avoiding duplicate content penalties with a new domain im working on.

    Thanks

  82. Fernando C said,

    December 3, 2007 @ 10:45 pm

    i tried doing the “.htaccess” and my server wont let me upload the file?

  83. Mana Media said,

    November 30, 2007 @ 11:32 am

    Dear Steven - thank you sooo much for all of the information supplied on this page. Much Appreciated.

    Team Mana Media

  84. naisioxerloro said,

    November 28, 2007 @ 5:12 pm

    Hi.
    Good design, who make it?

  85. Tim Lutz said,

    November 25, 2007 @ 9:11 pm

    I’ll add one more to the list of thank you’s for this. I could find lots of stuff on .htacess, but I’m hosted on a Windows server… The .asp script worked like a charm and I couldn’t find this type of help anywhere else!

  86. Liz said,

    November 25, 2007 @ 3:18 pm

    I just tried the htaccess solution and it works like a charm. Thanks for the straightforward advice.
    The problem was that a newsletter someone else sent out linked incorrectly to a page. The “.” was left out before the “php” so the address (in part) read “birdsphp” instead of “birds.php”
    Since the page uses php script, making a duplicate page to match the incorrect link wasn’t an option. Yet even with this messed up link, the redirect using .htaccess does the job.

  87. Hiren Adesara said,

    November 24, 2007 @ 8:30 am

    Hey,
    I want to redirect my university webpage to my blog. I tried creating a .htaccess file and putting that code into it and removing the existing index.html file. But still it doesnt work. Its still showing up the old index.html file. Can you please help?

    Hiren

  88. Tracey said,

    November 22, 2007 @ 12:45 pm

    So, how would you use a 302 redirect when you need to rewrite an unsightly URL?

  89. Sachin said,

    November 22, 2007 @ 4:10 am

    Hello,
    I want to redirect one html to another html page, so what code should i put in the HTML file? the files are on Windows server.
    Please help.

    Thank you,

    Sachin

  90. Steven Hargrove said,

    November 21, 2007 @ 11:27 pm

    David,

    You’re rankings haven’t been “lost” in the technical sense, however it is being “forwarded” to you’re new domain, or new page, this is a process that is not instant, and frankly I do not know the exact time.

    As for you’re page loading issue, you should consult with your web host provider.

    Hope that helps,
    Steve

  91. David said,

    November 20, 2007 @ 8:25 pm

    I used the Coldfusion solution about a week ago, now i have lost all my rankings . Also when i click on an old link that’s listed on a 3rd party website i can see the new page name appear in the url address bar but, the page fails to load. When viewing the page source i can see part of the page have been loaded.

    Any reason why ive lost my ranking and why my pages are not loading?

    Regards
    D

  92. Xstamper said,

    November 20, 2007 @ 2:41 pm

    Cool info. I’ll have to keep this in mind.

  93. jesper said,

    November 20, 2007 @ 3:28 am

    Hi Steven,

    Thanks for a great article. I am using 301 in php and asp.

    I browsed through all the previous replies but don’t think I saw anyone with my simple problem.

    A client’s website has been purchased by another company, and the old domain should point to the new domain. However, besides 301-redirecting to keep the indexed pages and pagerank, I want to be able to “add a page” with information to the user about the change… i.e. “Hi visitor. Company B has now purchased company A and the new website is located ad http://www.company-b.com“.

    Is there any way to do this? The current website is on windows server runnning asp.

    Thanks a lot,

    Jesper

  94. Matt Scilipoti said,

    November 16, 2007 @ 3:14 am

    As of [7820] on 2007/10/09, Rails has a new redirect option.

    # Examples:
    # redirect_to post_url(@post), :status=>:found
    # redirect_to :action=>’atom’, :status=>:moved_permanently
    # redirect_to post_url(@post), :status=>301
    # redirect_to :action=>’atom’, :status=>302

    http://dev.rubyonrails.org/changeset/7820

  95. Robb said,

    November 11, 2007 @ 7:34 am

    Can I get some advice re: 301 ASP.NET redirects? (never done a redir before)
    You say add this code to your page or script, which page? (probably a horribly stupid question, but everyone is a beginner sometime)

    If I have http://www.old.co.uk/blue.html - and I want anyone who keys in http://www.old.co.uk/blue.html to go to http://www.new.co.uk/blue-new.asp, where does the 301 ASP.NET code go, on the new site, the old site, where?

    I can understand the .htaccess concept ok, but not this part. If you can point me to a relevant source I’d really apreciate it, thanks.

  96. Derich said,

    November 7, 2007 @ 12:22 am

    Could I get some advice? I have about 25 domain names that are hosted in one location, using Linux, and 1 of the domain names managed by my ASP for the shopping cart solution in another location. For all intents and purposes, I don’t think any have any page rankings yet, but I wanted all of the remaining names to point to the shopping cart. Is a PHP or htaccess 301 redirect the best solution for this?
    I am also in the process of setting up SSL on the main domain name and I wanted to make sure that when the other names get indexed or spidered that any redirects wont negate the SSL. I don’t think it will but I am not an expert on this side of the business.

    Any help would be great….:)

  97. raul said,

    November 6, 2007 @ 6:12 pm

    http://www.drmagner.com
    i cant redirect all my html pages to php

  98. MeetHalima said,

    November 6, 2007 @ 5:34 pm

    That’s a pretty darn nifty how-to guide you got there. I used the “301 Redirect Using Mod_Rewrite” and it worked like a champ. Thanks a million. :)

  99. Internet Marketing Consultant said,

    November 6, 2007 @ 5:58 am

    Thanks for 301 redirect info.
    It really helped me.

  100. wrecked said,

    November 6, 2007 @ 2:43 am

    i want to redirect my websites http://autobuysell.wsnw.net/ to http://autobuysell.wsnw.net i tried but due to lack of programming language i was just able to revert it.

  101. Jayson said,

    November 2, 2007 @ 1:05 am

    In my control panel in bluehost I set up the 301 redirect. Do I need it on the web pages too? It’s just two domain names and no content?

  102. Vincent said,

    November 1, 2007 @ 4:30 am

    If i have only the domain name and no space then how can i redirect it to other website?

  103. Blogging Secret » How to Redirect a Web Page said,

    October 31, 2007 @ 7:04 pm

    […] best way to solve this problem is to set a 301 redirect, but I have never tried before as I have little confused about the coding of 301 […]

  104. Visitor235 said,

    October 30, 2007 @ 6:16 pm

    I have visited your site 234-times

  105. Corey said,

    October 26, 2007 @ 1:47 am

    I just finished moving a website and I used your PHP code snippits to do the redirects from the old site to the new site, it worked great! Thanks!

  106. Avi said,

    October 20, 2007 @ 10:42 am

    I couldn’t create a file named .htaccess , there couldn’t be a file with no name but extension, or I can put whatever I want in the file name?

  107. Ivan said,

    October 19, 2007 @ 9:19 pm

    That’s what I was looking for! The .htaccess redirect works great! Thank for posting this info.

  108. Iris said,

    October 17, 2007 @ 6:35 pm

    Steven, thank you for posting this solution. I had to forward old links from a different domain name, the 404 page didn’t work in IE7 (and only in IE7.) When I saw your page, I knew I had the answer.

    My client and I thank you!

  109. Mike said,

    October 15, 2007 @ 3:35 pm

    What if I am re-directing to a completely different domain/site? I noticed that yahoo has now picked my new domain in the listings, am I going to lose ranking? Because the site has different content…..but geared around the same content that I had on olds site.

    Thanks
    Mike

  110. naruto said,

    October 13, 2007 @ 9:53 pm

    this info was really useful, I am very satisfied with it, you even pasted a Perl code (the one that I use). thank you, very thank you! I can continue with a website project now.

  111. Andy said,

    October 11, 2007 @ 11:43 am

    Is there a “multile random url redirection” web-service out there?
    I would like to have one shorturl which redirects visitor randomly to my pages.
    Thanks.

  112. bryan smith said,

    October 3, 2007 @ 9:00 pm

    How do you do a redirect for a html/htm file to a PHP file?

  113. Pat said,

    October 3, 2007 @ 5:55 pm

    How can I apply this to Dreamweaver? Thanks.

  114. A “Basic” SEO Checklist | Alaska's Best SEO said,

    September 28, 2007 @ 11:28 am

    […] into the browser, it should redirect you to http://www.mygreatdomain.com using a SEO friendly 301 redirection […]

  115. Chris said,

    September 23, 2007 @ 2:39 am

    Is there a way to do the 301 redirect to redirect all pages that are *.html to *.php? In other words, wildcard it so anything they enter .html will get redirected to the same page in .php?

    Thanks!!

  116. Duncan said,

    September 21, 2007 @ 10:54 am

    Great information, clear and easy.
    Using the 301 in htaccess it is vital to get the URI’s correct without any inadvertent spaces in each of the addresses (Old + New), a space will throw a 500 Internal Server error.
    Found that out after a few heartstopping moments when testing.

    Thanks
    Duncan

  117. hiutopor said,

    September 18, 2007 @ 8:55 am

    Hi

    Very interesting information! Thanks!

    Bye

  118. barani said,

    September 17, 2007 @ 3:45 am

    hi all

  119. Eric said,

    September 15, 2007 @ 8:42 pm

    Very cool, I found this very helpful. Thanks!

  120. Steve said,

    September 12, 2007 @ 6:23 am

    …..just read the rest of the page on ASP and Java solutions……what a noob i am..!

  121. Steve said,

    September 12, 2007 @ 6:20 am

    what about windows servers?? You cant use .htaccess on those, so dead links or old pages have to be redirected somehow. HTTP html redirects are the only way. Yea, the site page gets reindexed but its better than having visitors view old pages or see HTTP errors. Can lose visitors permanently that way. I guess there needs to be a balance between SEO optimisation and visitor retention.

  122. Sumit Chauhan said,

    September 8, 2007 @ 8:21 am

    How can, I 301 redirect from http://www.xyz.com/shop.html?shop=http://www.abc.com/battery.asp
    to http://www.abc.com/battery.asp through ASP.net.

    Thanks,
    Sumit Chauhan

  123. Money | Car | Health » Blog Archive » Social Media Marketing Strategy #1: Re-Submitting Linkbaits for Viral Success said,

    September 7, 2007 @ 8:17 am

    […] you. Some of the social websites block the old url so create a new URL for your linkbait page and 301 redirect the old […]

  124. Social Media Marketing Strategy #1: Re-Submitting Linkbaits for Viral Success said,

    September 5, 2007 @ 5:29 pm

    […] you. Some of the social websites block the old url so create a new URL for your linkbait page and 301 redirect the old […]

  125. Dee Jarvo said,

    September 4, 2007 @ 5:38 pm

    I have a site on a windows server. Some of the links in google reflect the root URL (i.e. url.com) while others point to http://www.url.com. Is there a way to streamline the links to point just to the http://www.url.com the way htaccess does? Thanks!

  126. Archna Sajwan said,

    September 3, 2007 @ 12:51 am

    Thanks for the very useful information. This is what I’ve been looking for. Very well explained :-)

  127. Faith Emrich said,

    August 29, 2007 @ 10:30 am

    I just wanted to say a BIG THANK YOU for all of your insight and suggestions on this page. A department in our city had mailed out a survey to the community with an incorrect URL in it. I used the IIS redirection instructions to redirect them from the bad URL to the correct URL, and it worked beautifully. I have earmarked this page and you! Again, appreciate the help.

    Faith

  128. ruud said,

    August 26, 2007 @ 1:46 pm

    Hi,

    Thanks for informations.

    I’m looking for a diffirent redirection like this;

    if url has xxx word, visitor will redirect to main adress http://www.abc.com

    Please help about this subject.

    Thanks.

  129. spiderman05 said,

    August 11, 2007 @ 11:14 am

    Thank you very much for this tutorial. I switched my pages from HTML to PHP recently and was about to add HTML redirects to my old pages, though an inner voice kept telling me not to do so. I will try the .htaccess solution.

    Spiderman05

  130. MacMonkeyMark said,

    August 6, 2007 @ 6:56 am

    This is really cool. Thanks so much. But I have a question.

    Is it possible to do a redirect on a path? I have a PHP news script running and for all sorts of reasons, I’ve had to change the location of the updated news script. But the old path is still linked to around the net.

    Many visitors still come into this path: ../news/comments.php?id=(..any number between 1 and 600 right now)

    But I need them to come to this path../news3/comments.php?id=

    I can do the redirect just fine in the comments.php but it drops the “?id=…” part. Is this doable?

    Many thanks in advance!

  131. Brian Sharaga said,

    July 27, 2007 @ 11:40 am

    Hi Steven,

    I don’t know if this has been asked before. Windows doesn’t allow me to name a file “.htaccess”. It returns an error that says a file name is missing. I guess it requires the format: “filename.suffix” Is there any way to get around this error? I know AIX/Unix allows filenames that begin a dot.

  132. shery said,

    July 26, 2007 @ 1:41 pm

    thanks for the informations really helped me a lot.

  133. M Jo said,

    July 26, 2007 @ 1:13 pm

    I’m with JC also known as Conrad. That’s exactly what I’m looking for. I have the added problem, however, of having no access to any top level files at citymax. I think I can only get into the individual html pages. I’ve been looking at this subject for about six months and don’t know how best to do it.

  134. Conrad said,

    July 25, 2007 @ 4:16 am

    Hi Steve,

    I want to redirect every page in an old website to a new website that is totally different from the first one, so the paged do not correlate. I would like to have EVERY page in the old site redirected to the index.html in the new site. I tried options as found here, but so far I failed to have it work. Apprecciate your help.

    Thanks a lot!

    JC

  135. Ignite! » Using the 301 Redirect for Search Engine Optimization said,

    July 22, 2007 @ 10:33 pm

    […] http://www.stevenhargrove.com/redirect-web-pages […]

  136. Daniel Ciomek said,

    July 21, 2007 @ 11:10 pm

    Hi Steve,

    for the htaccess redirect, if you reorganized the whole site, and don’t remember all the older filenames, can you just use a “redirect all”, such as
    redirect 301 *.* http://www.newdomain.com (for all pages)
    or maybe
    redirect 301 /old1/*.* http://www.newdomain.com/new1/
    redirect 301 /old2/*.* http://www.newdomain.com/new2/ etc.?

    Would that work? Obviously you would point some targeted traffic to some more generic pages that way, but would it work? Also, is this a temorary setting (couple of month?), or do you have to leave it this way for eternaty?

  137. wings said,

    July 21, 2007 @ 5:11 pm

    i have bought a webdomain : mydomain.com and i wanted to redirect it to olddomain.com. but the service provider told me i cant and for that i should pay $5.5/month more to upgrade to web forwarding scheme. It seems not fare. Im wondering, if your webdomain do not redirect, so for what do they sell them without forwarding option? is there any other services so that i could be provided with webforwarding easily, or can i do any thing else for that? Answers are most welcomed.

  138. Steven Hargrove said,

    July 19, 2007 @ 9:02 am

    Dave Fury,

    Myspace only allows you access to the HTML of the page. There is no way of executing a 301 redirect on a myspace page.

  139. Dave Fury said,

    July 18, 2007 @ 11:48 pm

    What method can I use to redirect one myspace page to another?

  140. Thor Berntsson said,

    July 14, 2007 @ 1:46 pm

    Is this relevant for pages that I have already deleted or only for pages that I leave on the server with a redirect on it?

  141. x3me said,

    July 3, 2007 @ 4:10 pm

    how about in my page at geocities? its only a free site so theres no php i only use pure html coding? any idea?

  142. Bob THG said,

    July 3, 2007 @ 2:51 pm

    Howdy Steven.
    I have a few pages that are deleted and gone.
    I have cached pages of these files that still show up.
    You say you don’t do a redirect with an HTML page.
    How do I redirect to the new ones if the old ones are gone and it’s HTML?
    All these 404’s can’t be good for page ranking and indexing.
    Is robots.txt of any use?
    Also my site is on a Linex box.

    Thanks for your time and efforts - Bob

  143. TBird said,

    July 1, 2007 @ 5:49 pm

    Your rewrite 301 information helped me a great deal.

    Here’s a tip you may wish to add to your site:
    If the directory AND the filename are changing you will need TWO redirects. First for the directory, then the second one for the file

    Example:
    redirect 301 /wrong_dir/ http://www.mysite.com/right_dir/
    redirect 301 /right_dir/wrong_file.html http://www.mysite.com/right_dir/right_file.html

    Thanks again. -tbird

  144. links for 2007-06-27 | Mansoor Nathani's Blog said,

    June 26, 2007 @ 8:45 pm

    […] Steven Hargrove : How to redirect a web page, the smart way Over the past 4-6 years, use of meta tag refresh redirection has been abused for uses in relation to SPAM. The result of this and other scenarios of mis-uses of it, is that when using it, that page WILL be de-indexed from every search engine. (tags: apache htaccess) […]

  145. snow said,

    June 25, 2007 @ 5:26 pm

    Hi, I have looked up how to do 301 redirect with PHP on several sites. There code looks pretty much the same as yours expect for “header( “Status: 301 Moved Permanently” );”.

    What is this good for?
    Isn’t header( “HTTP/1.1 301 Moved Permanently” ); enough?

  146. Joe said,

    June 24, 2007 @ 11:33 am

    Hello:

    Thanks alot!
    But how can I make 301 redirect for the whole subdirectory to a new website?

    I need to redirect permanently some of the subdirectory, e.g.
    http://www.xyz.com/folder/ redirected to http://www.newsite.com
    (files in /folder/ are index.html, faq.html, base.html and there are also subfolders here)

    Thanks

  147. Chris said,

    June 23, 2007 @ 1:52 pm

    Very helpful indeed!

  148. The Greatest List Of Web Developer Resources | Self Made 20 Something said,

    June 21, 2007 @ 11:46 am

    […] Smart ways to redirect a webpage […]

  149. K-IntheHouse said,

    June 19, 2007 @ 2:15 pm

    Hi,

    Great post. I have a question regarding 301 redirect and pagerank. I recently updated my sitemap.xml so that all the urls are without the www prefix and I submitted it to Google. Now, my PR is 1 without the prefix and PR is 3 with the prefix. Is there a benefit to trying to adhere to one way or the other and have the mod rewrite do the rest?

    In my case, since my PR is higher with the prefix, I wonder if it is best to regenerate my Sitemap with the www and submit it again to Google. And have the mod rewrite put it place as well.

    What are your thoughts on this?

  150. nrgguxuhph said,

    June 18, 2007 @ 9:25 pm

    Hello! Good Site! Thanks you! bnkoieugxqgg

  151. TORCH said,

    June 16, 2007 @ 2:14 am

    Thank you! This info just saved me a bunch of frustration trying to link my websites to my online forum! Great info man!

  152. robert said,

    June 14, 2007 @ 4:01 am

    While your blog is for apache -
    For those of you who use Iplanet here are some notes for you:
    (these are being used on iplanet 6.1)

    To set all redirects to report as 301
    go to the /https/config
    Edit the obj.conf file and add

    Output fn=”set-variable” error=”301″ noaction=”true”

    after the line
    Now, any redirects you do in your obj.conf will be reported as 301’s.

    Couple of other options you can use in the obj.conf:
    Lets say you own domain zabix.com, then one day your site name was published in USA Today as zabex.com. Register zabex.com and update the DNS to point to your zabix.com web server.
    Now you could create a new VS for zabex.com but why have a second configuration to manage.
    In the obj.conf for zabix.com you can do this to redirect zabex.com to the correct domain.

    NameTrans fn=”redirect” from=”/” url=”http://www.zabix.com/”