N.Design Studio

301 .htaccess Redirect Trick

Filed in: Tricks & Tips Jump to comments

After the implementation of WordPress, you should notice some of the URLs and paths on this site are different. To prevent getting 404 File Not Found error (traffic coming from links, bookmarks and search engines), I used this .htaccess 301 redirect trick I found. This way is better than meta refresh or redirect tag because there is no delay as the browser reads the .htaccess file first. However, it is only available to Linux server (doen’t work on Window server). Here is the trick.

Go to your site’s root folder, download the .htaccess file to your local computer and edit it with a plain-text editor (Notepad). If you are using FTP Client software and you don’t see any .htaccess file on your server, double check your setting and make sure you have turn on invisible / system files.

To redirect certain page(s):

Redirect 301 /oldpage.html http://www.yoursite.com/newpage.html
Redirect 301 /oldpage2.html http://www.yoursite.com/folder/

To redirect entire site:

Redirect 301 / http://www.new-site.com/

52 comments so far

  1. Gravatar
    Ben
    # 1

    September 17th, 2006 at 12:30 pm

    Wow, like the tutorial nice :-]

  2. Gravatar
    Aaron
    # 2

    September 18th, 2006 at 9:22 pm

    Redirect in ColdFusion

  3. Gravatar
    bob
    # 3

    September 21st, 2006 at 4:52 pm

    lk

  4. Gravatar
    Sam
    # 4

    September 26th, 2006 at 5:49 pm

    Works on windows server if Apache is installed.

  5. Gravatar
    Pimm
    # 5

    September 30th, 2006 at 4:38 pm

    Apache can deal with much more complicated redirections…
    See this article:
    http://httpd.apache.org/docs/1.3/mod/mod_rewrite.html#RewriteEngine
    Or google ‘RewriteRule’

  6. Gravatar
    David Paul
    # 6

    October 6th, 2006 at 10:28 am

    I’ve done a guide on using htaccess files here:

    http://www.newearthonline.co.uk/article/68

  7. Gravatar
    David Paul
    # 7

    October 12th, 2006 at 2:25 am

    Not sure if it’s really related, but I’ve done a little article on how to use this redirect for scheduled maintenance so that the site appears to be down to everyone except for the person specified by an IP address so they can test it.

    http://www.newearthonline.co.uk/article/119

  8. Gravatar
    Min Thu
    # 8

    January 29th, 2007 at 6:09 am

    301 redirection is just simply effective and useful. thanks for sharing!

  9. Gravatar
    Broadband Wireless Help
    # 9

    May 22nd, 2007 at 6:56 am

    Great info Thanks, should help PR leaks

  10. Gravatar
    do
    # 10

    May 23rd, 2007 at 8:45 am

    Thanks!

  11. Gravatar
    metjay
    # 11

    June 5th, 2007 at 5:01 am

    “the browser reads the .htaccess file first”

    No browser can read a .htaccess file on a proper apache installation because they are never delivered out.
    .htacces files only are holding some server settings which are inherited in all subfolders of the containing one.
    So how does it redirect? The server makes a internal redirect, a kind of alias..

  12. Gravatar
    rajesh
    # 12

    July 12th, 2007 at 5:00 am

    That helped me

  13. Gravatar
    Nate
    # 13

    September 15th, 2007 at 12:32 am

    2 minor mistakes in this tutorial:

    The server reads the .htaccess file, not the client (browser).
    And yes this trick will work under windows with Apache.

  14. Gravatar
    Kyle
    # 14

    November 18th, 2007 at 9:19 pm

    Hi, wondering if i could use somthing like this to redirect all my Zip and rar files to my main page ? any info will be great thanks in advance.

  15. Gravatar
    vonchilliman
    # 15

    December 21st, 2007 at 12:01 pm

    Thank-you - Ideal information for me after renaming a page on my site :-)

  16. Gravatar
    Firefox
    # 16

    January 9th, 2008 at 7:59 am

    I’m experienced in SEO.
    I can tell you that this
    ::Redirect 301 / http://www.new-site.com/
    Is a bad way to redirect your site. You should use this code.

    Options +FollowSymLinks
    RewriteEngine on
    RewriteRule (.*) http://z.com/$1[R=301,L]

  17. Gravatar
    Fabian
    # 17

    February 24th, 2008 at 1:29 pm

    Maybe you should use this code if you move your whole site:
    Redirect Permanent 301 / http://www.new-site.com/

  18. Gravatar
    Jack Keller
    # 18

    May 13th, 2008 at 12:40 am

    I am glad I found this, momentary brainfreeze after sending out a mass mailing for a client site that had a + at the end of a link, which the server didn’t know to just strip off - YIKES!

    A quick .htaccess search and I came across a few overly complex solutions, yours was the most effective!

    Thanks a ton.

  19. Gravatar
    web design , almog , almog media
    # 19

    May 19th, 2008 at 9:05 pm

    This is really a good point , also helps with seo

  20. Gravatar
    Dragos
    # 20

    May 23rd, 2008 at 11:00 am

    Nice article!

  21. Gravatar
    energy certificate
    # 21

    July 18th, 2008 at 8:02 am

    nice article and helped :)

  22. Gravatar
    Free Article Directory
    # 22

    July 19th, 2008 at 2:25 am

    Thanks just what I was looking for!

  23. Gravatar
    Slots Guide
    # 23

    July 23rd, 2008 at 3:57 am

    Hi

    I’ve tried your code and it seems to be working, but I’m not sure that it is good for the SEs (Google, Yahoo, MSN). I’ve seen another code:

    RewriteEngine on
    # index.php to /
    RewriteCond %{THE_REQUEST} ^[A-Z]{3, 9}\ /.*index\.php\ HTTP/
    RewriteRule ^(.*)index\.php$ /$1 [R=301,L]

    What is your recommendation.
    Thanks

  24. Gravatar
    şapka
    # 24

    July 24th, 2008 at 9:13 am

    Great info Thanks, should help PR leaks

  25. Gravatar
    Hotcars
    # 25

    August 19th, 2008 at 7:52 pm

    Google will find the header info sent and they will see the 301 redirect. I dont know if its good. I know that if site is managed using cpanel its possible to make a nice 404 redirect to homepage without 301 or any other redirect things. There is 404.shtml file as I remember. Anyway thanks for this tip as it may be useful for those who don’t have cpanel.

  26. Gravatar
    Valerie
    # 26

    September 4th, 2008 at 3:41 pm

    Thanks so much for this! I kept finding such complicated code that didn’t seem to work for me, but this did the trick. I just needed to haul visitors from one to the other.

  27. Gravatar
    Michael
    # 27

    September 7th, 2008 at 3:27 pm

    Hello, regarding the form part, I have tried it and I am having trouble with it. First of Your tutourial was fantastic. Just where do I select were the email address goes?

  28. Gravatar
    Leena Ajwani
    # 28

    September 14th, 2008 at 3:08 pm

    i tried this

    redirect 301 /index.htm1 http://www.convert2xhtml.com/

    but it does not works not sure why?

  29. Gravatar
    CLS
    # 29

    September 26th, 2008 at 10:01 am

    Thanx indeed.

    And Slots Guide

    “I’ve tried your code and it seems to be working, but I’m not sure that it is good for the SEs (Google, Yahoo, MSN). I’ve seen another code:”

    The example given here a plain and simple 301 redirect is perfecto for SE’s

  30. Gravatar
    bilal
    # 30

    October 5th, 2008 at 10:19 am

    how do we redirect 404 pages to successfull 301 homepage ??
    so that we dont lose pagerank.

  31. Gravatar
    Dom
    # 31

    October 6th, 2008 at 1:24 pm

    I have to do a redirect, I need to change only the folders.

    www.mysite.com/12345/samehtml.html
    to
    www.mysite.com/54321/samehtml.html

    Does anyone know how to do this.

  32. Gravatar
    Noha
    # 32

    October 9th, 2008 at 6:00 am

    Hi all,
    i am trying to create a reserved section for a group of users to view extra pages of the blog like extra services so they have to get through a login page to access their part of the blog … i want to get them authenticated through ssl/https how can i do that with wordpress.

    thanks in advance

  33. Gravatar
    Social Networking Website for Charity
    # 33

    October 28th, 2008 at 1:42 pm

    Wowwww simply fantastic, these info will be useful for my site.

  34. Gravatar
    delilek online
    # 34

    October 31st, 2008 at 10:29 pm

    Great, I tried it on my site and it did work.
    Thank you for this code.

  35. Gravatar
    termal
    # 35

    November 3rd, 2008 at 5:18 pm

    I tried on my site and did it. Thanks for the code.

  36. Gravatar
    Marshall Reeves
    # 36

    November 10th, 2008 at 11:18 am

    Works very well - my indexed content deprecates appropriately, thanks! + Marshall Reeves

  37. Gravatar
    andy
    # 37

    November 15th, 2008 at 11:26 am

    It does work I use it on my site http://www.banksyunmasked.co.uk
    Make sure you put the file in the right place or you will get an internal server error.

  38. Gravatar
    decapper
    # 38

    November 21st, 2008 at 4:18 am

    Hello I was trying to redirect web 404 back to my home page http://www.pricelessweddings.com.au

  39. Gravatar
    John
    # 39

    November 24th, 2008 at 7:29 pm

    Yes it does work on my site as well.
    It does work I use it on my site www.canvastown.com

  40. Gravatar
    Jeff
    # 40

    November 28th, 2008 at 2:54 pm

    Yes works great thanks for the info.

  41. Gravatar
    Rohit
    # 41

    November 29th, 2008 at 2:45 am

    I m trying to redirect a link(contains some parameters along with) in my site. but its not taking ir properly.
    tell me, if in old and new URLs no. of parameter should be equal ?

  42. Gravatar
    Computer Tips
    # 42

    November 29th, 2008 at 11:01 pm

    Great tips and it works. Yay!

  43. Gravatar
    AK Designs
    # 43

    December 3rd, 2008 at 8:38 am

    Fantastic you cut out all the rubbish that normally surrounds 301 redirects. thanks.

  44. Gravatar
    Cristi
    # 44

    January 9th, 2009 at 10:17 am

    The browser doesn’t read the .htaccess file. The server does that.

  45. Gravatar
    Lots Of Freebies
    # 45

    January 12th, 2009 at 6:42 pm

    Nice and clear cut tutorial. Very easy to follow.

  46. Gravatar
    Website Design Web Development Company
    # 46

    March 19th, 2009 at 7:52 am

    Great tips for the newbies

  47. Gravatar
    birthday sms
    # 47

    April 22nd, 2009 at 5:32 am

    I have used this method before and i try to use it now, but it seems not working…

    I have to find why.

    I want to redirect old joomla pages to new static html pages

  48. Gravatar
    Kerwin
    # 48

    May 21st, 2009 at 9:57 pm

    very nice tip!

    but how come it aint working with mine too?

    i get 301 moved permanently even on my new domain. they are hosted on same server.

  49. Gravatar
    CORNx2
    # 49

    May 22nd, 2009 at 12:40 pm

    .htaccess files work for Apache web server installed on Linux, Mac or Windows

  50. Gravatar
    Cornel M
    # 50

    June 28th, 2009 at 8:08 am

    How you can’t see the .htaccess file in your FTP client??? You must be see all files!

  51. Gravatar
    Rock
    # 51

    July 13th, 2009 at 12:57 pm

    I have tried to use the .htaccess method of a 301 redirect in my Content Management System running on Unix, but it is still not working?

    Any Suggestions?

  52. Gravatar
    santosh
    # 52

    August 27th, 2009 at 9:26 am

    is it possible to have
    Redirect 301 /oldpage2.html /folder/abc.html

    instead of the whole url.
    if yes then what are the changes that one need to do.

Post your comment