301 Redirects

This is the cleanest way to redirect a URL. Quick, easy, and search-engine friendly. Remember HTAccess stuff is for Apache servers only.

Redirect a single page

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

Redirect an entire site

This way does it with links intact. That is www.oldsite.com/some/crazy/link.html will become www.newsite.com/some/crazy/link.html. This is extremely helpful when you are just "moving" a site to a new domain. Place this on the OLD site:

Redirect 301 / http://newsite.com/


  1. User Avatar
    Richard Razo
    Permalink to comment#

    How would you code a 301 redirect for the following?:
    I want to redirect “website.com/” and “website.com/index.html” to “website.com” for the index page to maximize search engine points.

  2. User Avatar
    Permalink to comment#

    Does this works the same when you use regular expressions? Maybe you should add another example.

  3. User Avatar
    Permalink to comment#

    Yes, this is really useful.

  4. User Avatar
    Permalink to comment#

    Thanks the first one is useful.. Was using redirection wordpress plugin but it was making my database bulky…

  5. User Avatar
    Permalink to comment#

    yes, I have apache server, (VPS)
    yes, I do have other .htaccess files on it and they all work
    no – this redirect line doesn’t do a thing

  6. User Avatar
    Priyank Sharma
    Permalink to comment#

    Works like a charm. Thanks for sharing!

  7. User Avatar
    Permalink to comment#

    I simply use html redirect pages that look like this:

    Forbidden Area

    • User Avatar
      Permalink to comment#

      Sorry html code wont show here:
      title Forbidden Area
      meta http-equiv=”refresh” content=”0; URL=http://www.The-Site-Name.com
      close body
      close html

    • User Avatar
      SEO Essex

      Are you not losing vital link juice though, as that method won’t tell any existing links that are pointing to the site to look at the new one.

      Correct me if I’m wrong.

    • User Avatar
      Permalink to comment#

      Tims method will drop your SEO rankings as it transfers 0% of the link juice on that page. Using a 301 redirect as stated in this post, it will pass on over 90% of all link juice.

  8. User Avatar
    Ryan Burnette

    This is the method I use for redirecting an entire site. It’s especially helpful when you have hundreds of possible URLs on one domain and you want to send them all to a new single location.

    redirectMatch 301 ^/ http://newsite.com

    Sometimes you just want to redirect from domain to domain with the permalink structure. Assuming you are able to use mod_rewrite, this should work.

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

  9. User Avatar
    Keshav Naidu
    Permalink to comment#

    Yes this is usefull, but better to giv with DEMO..

  10. User Avatar
    Shaneka Landell
    Permalink to comment#

    Hi how would you 301 redirect

    http://www.example.com to example.com

    I’m using Codeigniter framework, so i’m not sure if there’s a different process

    • User Avatar
      Lohith M
      Permalink to comment#


      try this in .htaccess file

      RewriteEngine On

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

      It might work for your query..

  11. User Avatar
    Jay Jalaram Extrusions
    Permalink to comment#

    Thanks it works, I have used it in my website Jay Jalaram Extrusions
    By redirecting http://jayjalaramext.com/contact.html which is old one to the new one http://jayjalaramext.com/contact-us

    Check it.

    • User Avatar
      Permalink to comment#


      This is exactly what I am trying to do, but am grappling with the example here. I have pages like /contact.html and they need to go to /contact-us as in your example as well as a host of other pages where the file name was changed slightly or in some cases no longer exists.

      Can you provide an example of the code you used? Many thanks for any help

  12. User Avatar
    Permalink to comment#

    @shaneka I think you are looking for the www to no-www snippet.


  13. User Avatar
    Daniel Winnard
    Permalink to comment#


    Just found this website for snippets. Awesome.

    I am having a problem which somebody might be able to help with.

    My company has just redeveloped our website. It is going all wordpress. However the initial site was in standard html and css. and we had a blog on a sub domain running wordpress.

    The problem now is we have deleted the sub domain for the blog as we are totally switching away from it. Some of its pages are listed in google. How would we redirect from blog.website.com to http://www.website.com using htaccess if no folder or sub domain now exists. Is this even possible?

    • User Avatar
      Permalink to comment#

      Yes you would use Redirect 301 /oldpage/ http://example.com/newpage/ as I need to do exactly the same thing on a site I’m converting to WordPress. It is precisely because the old url doesn’t work that you tell the search engines what the new url is to replace it. Did you manage to get this working?

      The issue for me is the amount of time it is going to take to redirect every single old page to the new page as the old site structure was different, sigh..

  14. User Avatar
    Dan Cornock
    Permalink to comment#

    Will this work for changing “www.sameDomain.com/feature.html” to “www.sameDomain.com/feature.php” ? And would I need to specify every page that the extension has changed?

  15. User Avatar
    Sithu raj

    Hi Richard Razo,
    For that canonicalization is the simple way.

  16. User Avatar
    Permalink to comment#

    I want to block or redirect potentially harmful outgoing flash links that I have no control of from htaccess.

    Any Ideas ?

  17. User Avatar
    Izdelava strani
    Permalink to comment#

    You can block sites that you do not want to have in search engines in robots.txt.
    Cause google is the main engine you should also check your website in “google webmaster tools”.

  18. User Avatar
    Permalink to comment#

    You can block sites that you do not want to have in search engines in robots.txt.

  19. User Avatar
    Debangshu Nag

    I am having a problem

    Redirect 301 /old-folder/page.jsp http://new-site/new-folder1/new-folder2/3d0ce71b-13c1-a0b2-e7c9-5125e3851f2c

    http://new-site/new-folder1/new-folder2/3d0ce71b-13c1-a0b2-e7c9-5125e3851f2c? /old-folder/page.jsp

    How can I remove the query string part that automatically concatenating.

  20. User Avatar
    Rayan beck

    The question sometimes arrises with clients “How permanent is a 301 permanent redirect?” Anotherwords, if at some future point, the client changes their mind for whatever reason, what are the consequences of changing a “permanent” redirect?

  21. User Avatar
    Roy M J
    Permalink to comment#

    What is the basic difference between a mod rewrite and a 301 rewrite? Ive been using mod rewrite method in htaccess.

  22. User Avatar

    Hi , I got this code to redirect domain.com/index to domain.com, but does not work. Can anyone tell me why?
    Below is the code

    RewriteCond %{THE_REQUEST} ^./index
    RewriteRule ^(.
    )index$ http://www.gsblagna.com/$1 [R=301]

  23. User Avatar

    thanks you very helpful i used the simple one line

    Redirect 301 /sample.html http://www.newsite.com

    thanks for sharing

  24. User Avatar
    Permalink to comment#

    Could this be applied to redirect from non www to www ? Something like:
    Redirect 301 myDomain.com http://www.myDomain.com

    or the short version: Redirect 301 / http://myDomain.com/

    Could this work? is it necessary to include http:// ?

  25. User Avatar
    Permalink to comment#

    Well i am transfering all of my data from old site to new one. including posts. i.e. i want to on site A there was a page called /mypage.html and i want that when user click on this url from search page it will be redirect to new site containing same page. I tried to do a 301 redirect using ” But its redirecting only main domain, please help me how can i redirect posts too? Regards

  26. User Avatar
    Kenneth von Rauch
    Permalink to comment#

    Redirects are great in terms of SEO and specifically 301 as opposed to 302. That said, you need to refrain from using redirects whenever possible because they don’t really retain all your Google juice. Just be sure to use it as last resort rather than a primal one. Again, I’m talking specifically about the search engine optimization aspect of the matter.

  27. User Avatar
    Permalink to comment#

    This is a must if you’re moving pages and don’t want to have a bunch of dead links. I use SEO spider to map all URLs on old website and then create 301 redirection for the one that don’t match anymore.

  28. User Avatar
    Permalink to comment#

    I used
    RewriteCond %{THE_REQUEST} \/index.html\ HTTP [NC]
    RewriteRule (.*)index.html$ /$1 [R=301,L]

    to remove index.html,
    and to redirect used
    Redirect 301 /old-file.html http://mywebsite.com (It works)
    But issue is,
    I just want to redirect

    Redirect 301 http://mywebsite.com/education/ http://mywebsite.com/education/why-go-waterless.html but doesn’t work. Anyone help please.

  29. User Avatar
    Permalink to comment#

    Someone please help me. I have a website that was done in coldfusion and I am trying to redirect to an html page. I have two problems, however: one problem is the following:

    Redirect 301 /tax_glossary.cfm http://www.mysite.com [R=301,L]

    and the other is:

    Redirect 301 /Margin-Accounts.9.htm http://www.mysite.com/margin-accounts.html [R=301,L]

    I have this at the beginning of the htaccess file:

    Options +FollowSymLinks
    RewriteEngine on
    RewriteRule http://www.mysite.com [R=301,L]

    I keep getting an internal server error.

    Any help would be greatly appreciated.

    Thank you

    • User Avatar
      Usama Ejaz

      remove “L” parameter.


      RewriteRule ^branches/kl$ /branches.php?s=kl [R=301]

  30. User Avatar
    Ben Racicot
    Permalink to comment#

    What about 301 redirects with masking enabled?

  31. User Avatar
    Ben M
    Permalink to comment#

    How do I get this to work when the directory being redirected has hyphens? So:




  32. User Avatar
    Permalink to comment#

    Thank you but how do i do some thing like





    and i have many urls like this with only domain change

  33. User Avatar
    Permalink to comment#

    I personally think using the htaccess method works better. Always do this on all my sites and have had no problems.

  34. User Avatar

    How to redirect this url
    from http://www.thexyz.com/our-brands.php (url not working)
    to http://www.xyz.com/our-brands.php (live url)

  35. User Avatar


    i have a query regarding redirection.
    i have site A and right now i redirected to Site B 301 permanent redirection.
    Now in site A i have a folder called “test” but that should not get redirect to Site B…
    how to stop avoiding from site A/particular folder to site B…
    we don have that folder in Site B so i am getting not found error.
    and i don want that folder url should not get redirect.. how to over come from this prob…
    Need help …………

  36. User Avatar
    Patrick McCoy
    Permalink to comment#

    If you’re keeping your same domain name and moving from a HTML site to a WP site, we’re manually coding in the 301’s. But, we have a WP blog on this HTML site that we added about a year ago, so the URL structure is domain.com/blog/title-of-article-here/ and we’re getting ready to remove the /blog directory since we don’t need it as the new website will be 100% WordPress. For this redirect sequence, we’re going to use the Simple 301 Redirects plugin which will now point domain.com/blog/title-of-article-here/ to domain.com/title-of-article-here/ to shorten the URL and make it a more focused URL for Google to see and have more of the article titles display in the SERPs. This is why we’re loving WordPress sites! – Patrick

  37. User Avatar
    Permalink to comment#

    I currently have a redirect set up as follows

    Redirect 301 /gb/41-fire-refuge-safety-signs http://rainbowsafety.co.uk/41-fire-refuge-safety-signs

    The above redirect works fine, however when I type in http://astonsafetysigns.co.uk/gb/41-fire-refuge-safety-signs
    I am redirected to http://rainbowsafety.co.uk/41-fire-refuge-safety-signs
    and want to be redirected to http://astonsafetysigns.co.uk/41-fire-refuge-safety-signs

    Is there a way in which this can be achieved?

    • User Avatar
      Neil McLeish
      Permalink to comment#

      Hi Jon.
      I am having a very similar issue. Did you manage to get this solved?
      If so, could you post the solution please, it would be a massive help?

      Many thanks in advance


  38. User Avatar
    Permalink to comment#

    I have an Ubuntu 12.04 box running 3 sites. One of them I need to force to use http://www.site.com vs just site.com. I have mod_rewrite is running and I have placed a .htaccess file in my /var/www/site directory with this code in it and restarted apache. Nothing, no effect. I even change the redirect to point at google just trying to see if it was working at all. Nothing. Any suggestions, do I have it in the wrong directory.. etc..

    Options +FollowSymLinks
    RewriteEngine On
    RewriteCond %{HTTP_HOST} ^site.com [NC]
    RewriteRule ^(.*)$ http://www.site.com/$1 [R=301,L]

  39. User Avatar
    Permalink to comment#

    How do I redirect all 404 errors in wordpress to my homepage?

    Do I have to do this in htaccess or some other place?

    Tried this code but it is not working :
    RewriteEngine on
    ErrorDocument 404 /index.php

  40. User Avatar
    Permalink to comment#

    I use the 301 redirect to remove “www” from the domain name. I noticed that css-tricks also have your “www” removed. I wonder if that have an effect on page popularity (link history) for older web pages with “www”.

  41. User Avatar
    S M Abu Sayeed
    Permalink to comment#

    How to redirect /~benchmak/catalog.html?page=shop.browse&category_id=62 to http://sitename.com/showroom/catalog ?
    Any help would be appreciated .

    Thanks in advance.

  42. User Avatar

    Hi there, hope that someone knows what I’m doing wrong:
    I have an old site (www.tehnomarket.com) that I would like to redirect to a new one (www.tehnomarket.com/novi), but when I try to do it like this it just goes into an infinite loop:
    RewriteEngine on
    RewriteCond %{HTTP_HOST} ^www.tehnomarket.com$ [OR]
    RewriteCond %{HTTP_HOST} ^tehnomarket.com$
    RewriteRule ^(.*)$ http://www.tehnomarket.com/novi/index.php/$1 [R=301,L]
    Thx :)

  43. User Avatar
    Louis Novick

    Simple yet effective. Thanks!

  44. User Avatar
    Permalink to comment#

    Scrolled allllll the way down here just so I could say THANKS!

  45. User Avatar

    Hi this is hrithik ..can somebody help me how to redirect magento product urls to wordpress woocommerce urls

    simply like http://example.com/index.php/shop/category/test1.html to http://example.us/shop/category/test1/

    we have bulk of products ( ~3000 products )which need 301 redirects

  46. User Avatar
    Permalink to comment#

    Hi there,

    I’m redesigning an old website entirely with WordPress. Urls will obviously be different. The current website has very good ranking in Google, will the method mentioned above keep the good ranking and seo the website currently has?


  47. User Avatar
    Frank Huang
    Permalink to comment#

    Am changing my site from html4 to html5 with a new directory. Content in all pages will remain the same but page URLs will all be different.

    Do I have to do a .htaccess file 301 Redirect for all the existing pages (to the new page) so status on search will remain the same (presumably) following the transition?

    Can give example code for a page?

    Thank you

  48. User Avatar
    Permalink to comment#

    Ok have html site – want to keep it’s index/.com but have all it’s subpages redirect to a WP site you see

    Is there a method to do this that is easy

  49. User Avatar
    Permalink to comment#

    Sorry if i am out i have thousands error 400 by changing the name of the redirect php file i have. problem is all error links does not exsist in my domain.
    Never had these links. Any way how can i redirect 301 with some lines all of them to my site, they all start with the same link, example:

    As you see all start with this redirect.php?url=


  50. User Avatar
    Permalink to comment#

    Forget to mention if this can be made with htacces?

  51. User Avatar
    Permalink to comment#

    hello all, i need the redirect to work based on the query string, for example how would I redirect this:


    into this:


    The new website is a WP site


  52. User Avatar
    Permalink to comment#

    If you want to test for 301 redirect or for any type of redirect you can use the redirect checker – https://www.minfolo.com/seo/redirect-checker

  53. User Avatar
    Dani Springer
    Permalink to comment#

    Thank you!

    Are you sure the whole URL is required if I’m redirecting within the same domain?

  54. User Avatar
    Michael Cooley
    Permalink to comment#

    I’m having trouble finding an example for redirecting a directory (not just a single page) from one website to a directory at another domain. To be specific, I want website.com/pettit/ to go to different-website.com/PETTIT/ – I’m doing it with an HTML redirect but would rather use .htaccess. Thanks!

  55. User Avatar
    Lucky Dagar



    how to redirect from company to company-profile.php page on same domain.

Leave a Comment

Posting Code!

You may write comments in Markdown. This makes code easy to post, as you can write inline code like `<div>this</div>` or multiline blocks of code in triple backtick fences (```) with double new lines before and after.

Code of Conduct

Absolutely anyone is welcome to submit a comment here. But not all comments will be posted. Think of it like writing a letter to the editor. All submitted comments will be read, but not all published. Published comments will be on-topic, helpful, and further the discussion or debate.

Want to tell us something privately?

Feel free to use our contact form. That's a great place to let us know about typos or anything off-topic.