Web Server

Set 301 Redirection using .htaccess File

There are several methods available using .htaccess file to redirect user from one page to another. 301 is one of the type to redirect user from one page to another.
301 Redirection also known as Permenant Redirection.

In this article we will see how to set up the 301 redirection from [code].htaccess[/code] file. 301 redirection can be setup in two different ways. We will see both the ways over here.

Unlike normal rewrite 301 redirection will change the URL in address bar.

Redirect Particular Page Using 301

If you want to redirect only some of the pages to be redirected to other page using 301 redirection then you can check below methods.

[cc lang=”apache”]
#Method 1
Redirect 301 /oldpage.html http://newsite.com/newpage.html

#Method 2
RewriteRule ^oldpage.html$ http://newsite.com/newpage.html [R=301]

[/cc]

Redirect Whole Site Using 301

If you are moving to new website and want all your visitor of old site being redirected to new site then here is the code for you . :)

[cc lang=”apache”]
#Method 1
Redirect 301 / http://newsite.com/

#Method 2
RewriteRule ^(.*)$ http://newsite.com/$1 [R=301,L]
[/cc]

Conclusion

So here are the two methods with which you can redirect your user from one page to another page or from one site to another site. Both will works fine so its totally up to you for which one to use in you project.

Subscribe to our RSS feed for more htaccess tricks.

Shares:
  • Mhabub
    March 28, 2012 at 11:19 pm

    I like this article, till now I was using .htaccess file for clean url.
    Hope to use this in future project if needed.

    Thanks,
    Mhabub

    Reply
  • Mhabub
    December 20, 2019 at 2:53 pm

    I like this article, till now I was using .htaccess file for clean url.
    Hope to use this in future project if needed.

    Thanks,
    Mhabub

    Reply
  • Peter
    February 6, 2013 at 5:04 pm

    Our previous website was built on a custom PHP-based CMS, can I redirect each page to relevant new page on my WordPress website. If so how much work is this? Or should I just redirect entire site to new home page, worried this is not good for SEO and goggle ranking.
    Any advice will be appreciated.
    Cheers Pete.

    Reply
    • Avinash
      February 10, 2013 at 3:33 pm

      Simply you can create pages with the same URL in WordPress.

      Reply
  • Peter
    December 20, 2019 at 2:55 pm

    Our previous website was built on a custom PHP-based CMS, can I redirect each page to relevant new page on my WordPress website. If so how much work is this? Or should I just redirect entire site to new home page, worried this is not good for SEO and goggle ranking.
    Any advice will be appreciated.
    Cheers Pete.

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *