{"id":102,"date":"2019-05-26T21:59:17","date_gmt":"2019-05-26T21:59:17","guid":{"rendered":"https:\/\/harshitpeer.com\/blog\/?p=102"},"modified":"2019-07-19T15:06:09","modified_gmt":"2019-07-19T15:06:09","slug":"how-to-redirect-all-traffic-to-the-new-website-using-htaccess","status":"publish","type":"post","link":"https:\/\/harshitpeer.com\/blog\/how-to-redirect-all-traffic-to-the-new-website-using-htaccess\/","title":{"rendered":"How to redirect all traffic to the new website using .htaccess?"},"content":{"rendered":"\n<p>It&#8217;s very rare that anyone changes the main domain of the website, but it&#8217;s still possible. The main issue which you may face while shifting to a new domain is how to redirect all traffic, that is old URLs to their appropriate new URLs. <\/p>\n\n\n\n<p>For example, yourolddomain.com\/some_blog_post should NOT redirect to just yournewdomain.com<\/p>\n\n\n\n<!--more-->\n\n\n\n<p>Ideally, it should redirect to yournewdomain.com\/some_blog_post<\/p>\n\n\n\n<p>You may ask why it&#8217;s necessary to redirect exactly to the same page? Well, good question. It&#8217;s important from an SEO viewpoint. If your old domain is very old, chances are that you must be having some good SEO score, and you don&#8217;t want that to go to drain. Using exact redirection, we can borrow the old site SEO score to the new site. This is also important to maintain the search listing location on Google and similar search engine websites.<\/p>\n\n\n\n<p>Now, let&#8217;s get to the good stuff, how to redirect?<\/p>\n\n\n\n<p>Requirements: Knowledge of creating a file on the server, hosting for the old domain.<\/p>\n\n\n\n<p>If you are using <a href=\"https:\/\/en.wikipedia.org\/wiki\/CPanel\" target=\"_blank\" rel=\"noreferrer noopener\" aria-label=\"cPanel (opens in a new tab)\">cPanel<\/a>, you can easily follow the below tutorial. If you are using other control panels or FTP, the process is very similar.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Steps<\/strong><\/h3>\n\n\n\n<p>Login to cPanel, go to File Manager and navigate to your root directory of the domain. (Usually, it is something like public_html or public)<\/p>\n\n\n\n<p>Create a new file .htaccess<\/p>\n\n\n\n<p>Edit that newly created file and paste the following content.<\/p>\n\n\n<pre>RewriteEngine on <br>RewriteRule ^(.*)$ http:\/\/NEWDOMAIN.COM\/$1 [R=301,L]<\/pre>\n\n\n<p>Make sure you change NEWDOMAIN.COM with your own domain name.<\/p>\n\n\n\n<p>In case if you are not able to see .htaccess file, click on &#8220;Settings&#8221; button (top right corner) and enable checkbox &#8220;Show Hidden Files&#8221;<\/p>\n\n\n\n<p>That&#8217;s it! Now, check if all the links are redirecting properly or not. You can do the same process for any subdomains you have on your website.<\/p>\n\n\n\n<p>Using .htaccess is one of the simplest ways to redirect traffic. However, you can also utilize other methods like DNS, Domain provider&#8217;s redirection, etc. <\/p>\n\n\n\n<p>If you want to know more about what is htaccess all about, you can read this fantastic article on WPBeginner &#8211; <a href=\"https:\/\/www.wpbeginner.com\/glossary\/htaccess\/\" target=\"_blank\" rel=\"noreferrer noopener\" aria-label=\"What is htaccess in WordPress?  (opens in a new tab)\">What is htaccess in WordPress? <\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>It&#8217;s very rare that anyone changes the main domain of the website, but it&#8217;s still possible. The main issue which [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":103,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"default","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","ast-disable-related-posts":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"default","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"footnotes":""},"categories":[45],"tags":[64,65,67,66,63,69],"class_list":["post-102","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-technology-tips","tag-htaccess","tag-new-website","tag-old-to-new","tag-redirect","tag-redirect-old-site","tag-website"],"_links":{"self":[{"href":"https:\/\/harshitpeer.com\/blog\/wp-json\/wp\/v2\/posts\/102","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/harshitpeer.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/harshitpeer.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/harshitpeer.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/harshitpeer.com\/blog\/wp-json\/wp\/v2\/comments?post=102"}],"version-history":[{"count":4,"href":"https:\/\/harshitpeer.com\/blog\/wp-json\/wp\/v2\/posts\/102\/revisions"}],"predecessor-version":[{"id":113,"href":"https:\/\/harshitpeer.com\/blog\/wp-json\/wp\/v2\/posts\/102\/revisions\/113"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/harshitpeer.com\/blog\/wp-json\/wp\/v2\/media\/103"}],"wp:attachment":[{"href":"https:\/\/harshitpeer.com\/blog\/wp-json\/wp\/v2\/media?parent=102"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/harshitpeer.com\/blog\/wp-json\/wp\/v2\/categories?post=102"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/harshitpeer.com\/blog\/wp-json\/wp\/v2\/tags?post=102"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}