<\/figure><\/div>\n\n\n\nIf this works for you, you can stop the tutorial now.<\/p>\n\n\n\n
We'll proceed with the tutorial as if you haven't done the domain forwarding.<\/p>\n\n\n\n
Point the nameservers of the old domain to your host<\/h2>\n\n\n\n You might have space to add an addon domain at the same host you use for the destination domain. That's typically where I prefer to host this redirect, just to keep things in one spot.<\/p>\n\n\n\n
It's perfectly fine for you to host the old domain where it was or at another host.<\/p>\n\n\n\n
The main thing is it has cPanel. If it's a Windows IIS server, Parallels or something else, the implementation will be different from what's shown here.<\/p>\n\n\n\n
In DNS Management<\/em>, click \"Change\" next to the nameservers.<\/p>\n\n\n\n <\/figure><\/div>\n\n\n\nSwitch from Default nameservers to Custom nameservers.<\/p>\n\n\n\n
<\/figure><\/div>\n\n\n\nWhen you setup the host, you would've received an email listing the two or more nameservers for that hosting account.<\/p>\n\n\n\n
If you can't find the email, you might be able to find it in the sidebar of your cPanel. It will probably be listed under Primary<\/em> and Secondary Nameservers<\/em>.<\/p>\n\n\n\nFor the purpose of this tutorial, I'll be using<\/p>\n\n\n\n
ns8439.hostgator.com\nns8440.hostgator.com<\/code><\/pre>\n\n\n\nThere will usually be two nameservers, sometimes three or more.<\/p>\n\n\n\n
Enter the nameservers at the domain registrar as shown and click \"Save\".<\/p>\n\n\n\n
<\/figure><\/div>\n\n\n\nAdd the old domain to the host<\/h2>\n\n\n\n While the DNS is propagating, go to where you'll be hosting the old domain.<\/p>\n\n\n\n
Assuming it's not already setup at that host, and that it's not the primary domain, set it up as an Addon Domain by going to Addon Domains<\/em>.<\/p>\n\n\n\n <\/figure><\/div>\n\n\n\nEnter the old domain in New Domain Name<\/em>. Everything else should be fine as default.<\/p>\n\n\n\nThere's no reason to create a new FTP account for this domain.<\/p>\n\n\n\n
Click \"Add Domain\".<\/p>\n\n\n\n
<\/figure><\/div>\n\n\n\nIf everything's good, you'll see a success message.<\/p>\n\n\n\n
<\/figure><\/div>\n\n\n\nAdd the .htaccess file to the old domain<\/h2>\n\n\n\n Now to add the code that will actually do the redirecting.<\/p>\n\n\n\n
Go to File Manager<\/em>.<\/p>\n\n\n\n <\/figure><\/div>\n\n\n\nNavigate to the folder you added for the old domain in the Addon Domains<\/em> step.<\/p>\n\n\n\n <\/figure><\/div>\n\n\n\nHostGator already had a .htaccess<\/em> file in the folder, so you just select it and click Edit<\/em>.<\/p>\n\n\n\n <\/figure><\/div>\n\n\n\nIf you don't have a .htaccess<\/em> file there, first check you can see hidden files, by going to Settings<\/em> (in File Manager<\/em>) and checking Show Hidden Files (dotfiles)<\/em>.<\/p>\n\n\n\n <\/figure><\/div>\n\n\n\nIf you still can't see a .htaccess<\/em> file in the home folder for the domain, click \"+ File\" and create one.<\/p>\n\n\n\nIn .htaccess<\/em>, add the following code:<\/p>\n\n\n\nRewriteEngine on\nRewriteRule ^(.*)$ https:\/\/www.yourdomain.com\/$1 [R=301,L]<\/code><\/pre>\n\n\n\nThe key line is RewriteRule<\/em>.<\/p>\n\n\n\nThe line says using ^(.*)$<\/em> \"take the whole page, not including the domain...\"<\/p>\n\n\n\n\"... and stick it where the $1<\/em> is\".<\/p>\n\n\n\nSo if someone goes to https:\/\/old.com\/important-page\/ the code will take important-page\/<\/em> and tack it on to the end of https:\/\/www.newdomain.com\/ so the visitor ends up on https:\/\/www.newdomain.com\/important-page\/<\/p>\n\n\n\nBe sure to change https:\/\/www.newdomain.com<\/em> in the code to your new domain.<\/p>\n\n\n\nAs you can see, I've changed mine to intelliwolf.com.<\/p>\n\n\n\n
Click \"Save Changes\".<\/p>\n\n\n\n
<\/figure><\/div>\n\n\n\nAdd blank index.php file<\/h2>\n\n\n\n For an added layer of security, I don't like to leave a domain empty like this.<\/p>\n\n\n\n
You should always add a file like index.html<\/em> or index.php<\/em> even if it's blank.<\/p>\n\n\n\nWhen you do that, if something goes wrong with the .htaccess redirect and it doesn't end up redirecting, anyone going to the old domain will just see a blank page, rather than a listing of all the files in there.<\/p>\n\n\n\n
Click \"+ File\" to add a new file.<\/p>\n\n\n\n
<\/figure><\/div>\n\n\n\nCall the new file index.php<\/em> and click \"Create New File\".<\/p>\n\n\n\n <\/figure><\/div>\n\n\n\nYou don't have to add anything into this file. If everything goes well, no one will ever see it.<\/p>\n\n\n\n
It may take a few hours for the redirect to start working.<\/p>\n\n\n\n
The domain registrar has to tell all the other DNS phonebooks that your old domain is now located at the new host.<\/p>\n\n\n\n
Once that's done, you probably won't need to touch it again. There's nothing to update and this code has worked for the 20-odd years I've been building websites.<\/p>\n\n\n\n
How to redirect a specific page to another domain with .htaccess<\/h2>\n\n\n\n If you want to redirect just one page from the old domain to somewhere different, you just need one line:<\/p>\n\n\n\n
Redirect 301 \/old-url\/ http:\/\/newdomain.com\/new-url\/<\/code><\/pre>\n\n\n\nReplace \/old-url\/<\/em> with whatever comes after the domain for the URL you want to redirect from.<\/p>\n\n\n\nThen put the full URL of the destination page.<\/p>\n\n\n\n
You can use this independently of the domain redirect I showed at the start.<\/p>\n\n\n\n
If, instead of redirecting the entire site, you just wanted to redirect one URL from the old domain (maybe it was on your business cards), then you could just put this line in the .htaccess<\/em> instead of the RewriteRule<\/em> line.<\/p>\n","protected":false},"excerpt":{"rendered":"Redirecting pages or websites tends not to be something most web designers deal with on a regular basis. What sometimes happens is you change your domain and keep the pages the same on the new domain. You don’t want to redirect all the pages of the old domain to the homepage of the new domain,<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[11],"tags":[],"yoast_head":"\n
htaccess Redirect to Another Domain: How To Guide<\/title>\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n\t \n\t \n\t \n