Internet, Networking, & Security Web Development How to Redirect an Entire Site Using HTAccess Configure 301 from htaccess By Jennifer Kyrnin Freelance Contributor Jennifer Kyrnin is a professional web developer who assists others in learning web design, HTML, CSS, and XML. our editorial process LinkedIn Jennifer Kyrnin Updated March 06, 2020 Thomas Barwick / Getty Images Web Development CSS & HTML Web Design SQL Tweet Share Email If you have a website you want to move to a new domain, one of the easiest ways to do it is with a 301 redirect in a .htaccess file in your web server root. 301 Redirects Are Important It's important that you use a 301 redirect rather than a meta refresh or other type of redirect. This tells search engines that the pages have been permanently moved to a new location. Google and other search engines will then update their indexes to use the new domain without changing your indexing values. So, if your old website was ranking fairly well on Google, it will continue to rank well after the redirect is indexed. We have used 301 redirects for many of the pages on this site with no change in their rankings. Difficulty: AverageTime Required: 15 minutes Here's How Place all your content on the new domain using the same directory structure and file names as the old domain. This is the most important step. In order for this 301 redirect to work, the domains need to be identical in file structure. You might also consider putting in a noindex, nofollow robots.txt file on this new domain until you've got the redirect set up. This will ensure that Google and other search engines don't index the second domain and penalize you for duplicate content. But if you don't have a lot of content, or can get all the content copied over in a day or so, this isn't as important. On your old domain website, open up the .htaccess file in your root directory with a text editor — if you don't have a file called .htaccess (note the dot at the front), create one. This file may be hidden in your directory list. Add the line: redirect 301 / http://www.new domain.com/ to the .htaccess file at the top. Change the URL http://www.new domain.com/ to the new domain name you're redirecting to. Save the file to the root of your old website. Test that the old domain pages now point to the new domain. Depending on your server configuration, you may need to restart Apache for the change to take effect.