{"id":584,"date":"2022-01-21T19:00:50","date_gmt":"2022-01-21T18:00:50","guid":{"rendered":"https:\/\/servikus.com\/tutorials\/?p=584"},"modified":"2022-01-22T18:50:26","modified_gmt":"2022-01-22T17:50:26","slug":"301-redirection-in-from-old-to-a-new-domain-htaccess","status":"publish","type":"post","link":"https:\/\/servikus.com\/tutorials\/301-redirection-in-from-old-to-a-new-domain-htaccess\/","title":{"rendered":"301 Redirection in from old to a new domain (.htaccess)"},"content":{"rendered":"\n<p>For instance, you have two domains &#8211; testingaddondomain.com (old domain) and addondomain.com (new domain). You want to make that, once you type the old domain, a new domain appears in the browser, and that it shows the content of the old domain. <\/p>\n\n\n\n<p>If you don&#8217;t have a directory and new domain on your account, you can <a href=\"https:\/\/servikus.com\/tutorials\/adding-an-addon-domain-in-cpanel\/\" target=\"_blank\" rel=\"noreferrer noopener\">add it as an addon domain<\/a>. You can check our previous tutorial on how to add it.<\/p>\n\n\n\n<p>Here is how you can do it if you already have the domains added to your cPanel account.<\/p>\n\n\n\n<p>1. Log in to your cPanel account, then to <strong>File Manager<\/strong>. Navigate to the directory of the domain (in this case testingaddondomain.com) which you wish to redirect to a new domain.<\/p>\n\n\n\n<p>2. Click on the <strong>Settings <\/strong>button and make sure that you check the box &#8220;Show Hidden Files&#8221;, so you can move all the files.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full is-resized\"><a href=\"https:\/\/servikus.com\/tutorials\/wp-content\/uploads\/2022\/01\/301-redirection-old-domain-to-new-domain-1-Servikus-tutorials.png\"><img src=\"https:\/\/servikus.com\/tutorials\/wp-content\/uploads\/2022\/01\/301-redirection-old-domain-to-new-domain-1-Servikus-tutorials.png\" alt=\"\" class=\"wp-image-586\" width=\"600\" srcset=\"https:\/\/servikus.com\/tutorials\/wp-content\/uploads\/2022\/01\/301-redirection-old-domain-to-new-domain-1-Servikus-tutorials.png 616w, https:\/\/servikus.com\/tutorials\/wp-content\/uploads\/2022\/01\/301-redirection-old-domain-to-new-domain-1-Servikus-tutorials-300x201.png 300w\" sizes=\"(max-width: 616px) 100vw, 616px\" \/><\/a><\/figure>\n\n\n\n<p>3. Click <strong>Select All<\/strong>, then click <strong>Move<\/strong>. You will need to enter a <strong>path <\/strong>to the directory where your new domain is located (in this case it&#8217;s home\/addondomain.com). Click <strong>Move Files<\/strong>.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large is-resized\"><a href=\"https:\/\/servikus.com\/tutorials\/wp-content\/uploads\/2022\/01\/301-redirection-old-domain-to-new-domain-Servikus-tutorials.png\"><img src=\"https:\/\/servikus.com\/tutorials\/wp-content\/uploads\/2022\/01\/301-redirection-old-domain-to-new-domain-Servikus-tutorials-1024x479.png\" alt=\"\" class=\"wp-image-588\" width=\"600\" srcset=\"https:\/\/servikus.com\/tutorials\/wp-content\/uploads\/2022\/01\/301-redirection-old-domain-to-new-domain-Servikus-tutorials-1024x479.png 1024w, https:\/\/servikus.com\/tutorials\/wp-content\/uploads\/2022\/01\/301-redirection-old-domain-to-new-domain-Servikus-tutorials-300x140.png 300w, https:\/\/servikus.com\/tutorials\/wp-content\/uploads\/2022\/01\/301-redirection-old-domain-to-new-domain-Servikus-tutorials-768x359.png 768w, https:\/\/servikus.com\/tutorials\/wp-content\/uploads\/2022\/01\/301-redirection-old-domain-to-new-domain-Servikus-tutorials-1536x718.png 1536w, https:\/\/servikus.com\/tutorials\/wp-content\/uploads\/2022\/01\/301-redirection-old-domain-to-new-domain-Servikus-tutorials.png 1889w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/a><\/figure>\n\n\n\n<p>4. Once you do that, the directory will remain empty. You need to create a new file called .<strong>htaccess<\/strong>. Press the button in the top left corner to create it. <\/p>\n\n\n\n<p><em>Note<\/em>: Don&#8217;t forget <strong>the dot<\/strong> in the name, as the file will not work properly without it.<\/p>\n\n\n\n<p>5. When you have created the file, click on it, then click on the <strong>Edit<\/strong> button from the top menu. The system will ask you to confirm and press Edit one more time.<\/p>\n\n\n\n<p>6. Paste the following code into that file, then <strong>replace <\/strong>the olddomain.com and newdomain.com with your domain names, then save the file.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">&lt;IfModule mod_rewrite.c>\n  RewriteEngine On\n  RewriteCond %{HTTPS_HOST} ^olddomain.com$ [OR]\n  RewriteCond %{HTTPS_HOST} ^www.olddomain.com$\n  RewriteRule (.*)$ https:\/\/www.newdomain.com\/$1 [R=301,L]\n&lt;\/IfModule>\n<\/pre>\n\n\n\n<p>7. Next, you need to find the name of your <strong>website&#8217;s database<\/strong> to make a few changes. To do that, navigate to the directory where you moved the website&#8217;s content. Find the <strong>wp_config.php<\/strong> file and click <strong>View<\/strong>. You will find your database name next to this parameter <strong>&#8216;DB_NAME&#8217;<\/strong> (in this case celebfre_wp746). Also, you can find your <strong>table prefix<\/strong> in this file if you scroll down. You will need it for the next step to edit the particular table, <em>tableprefix_options<\/em>. Usually, the prefix is <em>wp_<\/em>. In this case, it is <\/p>\n\n\n\n<p>$table_prefix = &#8216;wptz_&#8217;<\/p>\n\n\n\n<p>8. Go back to the cPanel dashboard and find <strong>phpMyAdmin<\/strong>. Find your database by its name and select it. Find the table called <em>wptz_options<\/em> in this case (most of the time it is <em>wp_options<\/em> if don&#8217;t know your table prefix) and click on the name or the &#8216;+&#8217; to expand it. You need to change the URLs for <strong>siteurl <\/strong>and <strong>home <\/strong><em>option_values<\/em>. You will need to change one option at a time. <\/p>\n\n\n\n<figure class=\"wp-block-image size-large is-resized\"><a href=\"https:\/\/servikus.com\/tutorials\/wp-content\/uploads\/2022\/01\/301-redirection-old-domain-to-new-domain-2-Servikus-tutorials.png\"><img src=\"https:\/\/servikus.com\/tutorials\/wp-content\/uploads\/2022\/01\/301-redirection-old-domain-to-new-domain-2-Servikus-tutorials-1024x447.png\" alt=\"\" class=\"wp-image-595\" width=\"600\" srcset=\"https:\/\/servikus.com\/tutorials\/wp-content\/uploads\/2022\/01\/301-redirection-old-domain-to-new-domain-2-Servikus-tutorials-1024x447.png 1024w, https:\/\/servikus.com\/tutorials\/wp-content\/uploads\/2022\/01\/301-redirection-old-domain-to-new-domain-2-Servikus-tutorials-300x131.png 300w, https:\/\/servikus.com\/tutorials\/wp-content\/uploads\/2022\/01\/301-redirection-old-domain-to-new-domain-2-Servikus-tutorials-768x335.png 768w, https:\/\/servikus.com\/tutorials\/wp-content\/uploads\/2022\/01\/301-redirection-old-domain-to-new-domain-2-Servikus-tutorials.png 1277w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/a><\/figure>\n\n\n\n<p>9. To make a change, click <strong>Edit<\/strong>, put the URL of your new domain instead of an old one (in this case https:\/\/addondomain.com) and click <strong>Go<\/strong>. Do the same for the home option.<\/p>\n\n\n\n<p>10. Check if your redirection works by typing the old domain to the browser (it should show the website and the new domain) and you are set! <\/p>\n\n\n\n<p>In case you are having difficulties with making a redirection, you can always reach out to Servikus&#8217; support to help you out with it.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>For instance, you have two domains &#8211; testingaddondomain.com (old domain) and addondomain.com (new domain). You want to make that, once you type the old domain, a new domain appears in the browser, and that it shows the content of the old domain. If you don&#8217;t have a directory and new domain on your account, you&#8230; <a class=\"read-more\" href=\"https:\/\/servikus.com\/tutorials\/301-redirection-in-from-old-to-a-new-domain-htaccess\/\">Read More<\/a><\/p>\n","protected":false},"author":1001,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[7,2,9],"tags":[],"_links":{"self":[{"href":"https:\/\/servikus.com\/tutorials\/wp-json\/wp\/v2\/posts\/584"}],"collection":[{"href":"https:\/\/servikus.com\/tutorials\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/servikus.com\/tutorials\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/servikus.com\/tutorials\/wp-json\/wp\/v2\/users\/1001"}],"replies":[{"embeddable":true,"href":"https:\/\/servikus.com\/tutorials\/wp-json\/wp\/v2\/comments?post=584"}],"version-history":[{"count":24,"href":"https:\/\/servikus.com\/tutorials\/wp-json\/wp\/v2\/posts\/584\/revisions"}],"predecessor-version":[{"id":623,"href":"https:\/\/servikus.com\/tutorials\/wp-json\/wp\/v2\/posts\/584\/revisions\/623"}],"wp:attachment":[{"href":"https:\/\/servikus.com\/tutorials\/wp-json\/wp\/v2\/media?parent=584"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/servikus.com\/tutorials\/wp-json\/wp\/v2\/categories?post=584"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/servikus.com\/tutorials\/wp-json\/wp\/v2\/tags?post=584"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}