Science, Tech, Math › Computer Science How to Redirect an Entire Site Using HTAccess Configure 301 from htaccess Share Flipboard Email Print Thomas Barwick / Getty Images Science, Tech, Math PHP Programming Perl Python Java Programming Javascript Programming Delphi Programming C & C++ Programming Ruby Programming Visual Basic View More By Jennifer Kyrnin Jennifer Kyrnin Writer University of California University of Washington Jennifer Kyrnin is a professional web developer who assists others in learning web design, HTML, CSS, and XML. Learn about our Editorial Process Updated on March 06, 2020 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. Cite this Article Format mla apa chicago Your Citation Kyrnin, Jennifer. "How to Redirect an Entire Site Using HTAccess." ThoughtCo, Apr. 5, 2023, thoughtco.com/redirect-entire-site-using-htaccess-3467923. Kyrnin, Jennifer. (2023, April 5). How to Redirect an Entire Site Using HTAccess. Retrieved from https://www.thoughtco.com/redirect-entire-site-using-htaccess-3467923 Kyrnin, Jennifer. "How to Redirect an Entire Site Using HTAccess." ThoughtCo. https://www.thoughtco.com/redirect-entire-site-using-htaccess-3467923 (accessed May 29, 2023). copy citation