How to Redirect an Entire Website Using HTAccess

Redirect Site Using HTAccess – This document explains how to create a .htaccess file to redirect the content of your site or site. This will not redirect any email for your domains. A permanent 301 redirect to your .htaccess file allows search engines and others to know that an old link has been replaced by a new one. This is the recommended way to direct traffic from an existing page. Before beginning How to Redirect Site Using HTAccess please read me note below.

README – Note

As a configuration file, .htaccess is very powerful. Even the slightest syntax error (such as a missing space) can cause your content to not display correctly or not be displayed at all.

As .htaccess is a hidden system file, make sure that your FTP client is configured to show the hidden files. This is usually an option in the preferences/options of the program.

Also Read: How to Optimize Website for Google

If you want to move a website to a new domain, one of the easiest and most effective ways is to perform a 301 redirect in a .htaccess file from the root of your web server.

301 redirects are important to Redirect Site Using HTAccess

It is important to use a redirect 301 instead of a meta-refresh or other type of redirection. This tells the search engines that the pages have been moved permanently to a new location. Google and other search engines will update their indexes to use the new domain without changing their indexing values. Therefore, if your previous website was ranked well on Google, it would continue to rank well after indexing the redirect. Personally, I have used 301 redirects for most of the pages on this site without changing their classification.

  • Difficulty: Average
  • Time Required: 15 minutes

How to Redirect an Entire Site Using HTAccess Using 301 Redirect

  1. Place all your content in the new domain using the same directory structure and file names as the previous domain. This is the most important step. For this 301 redirect to work, the domains must be identical in the structure of the file.
    Note: You can also consider placing a robots.txt noindex, nofollow file in this new domain until the redirect is configured. This will ensure that Google and other search engines do not index the second domain and penalize it for duplicate content. But if you do not have much content or if you can copy all the content in a day or two, it’s not that important.
  2. On your old domain website, open the .htaccess file in your root directory with a text editor; If you do not have a file called .htaccess (look at the point in front), create one. This file may be hidden in your list of directories.
  3. Add the line:
    redirect 301 / http://www.yourdomain.com/
    to the .htaccess file at the top.
  4. Change the URL
    http://www.yourdomain.com/
    the new domain name to which you are redirecting.
  5. That’s it!
  6. Save the file to the root of your previous website.
  7. Verify that the previous old domain pages now point to the new domain.
  8. Note: Make sure to update your webmaster for example – Google Webmaster so that you don’t lose SEO.

Redirect Site Using HTAccess

Alternate Method – How to Redirect Site Using HTAccess but exclude one or more directories

Personal experience – We recently wanted to move a website to a new domain and automatically send visitors and Googlebot to the new content, but some resources had to stay in the current domain. This meant that we had to redirect all requests to the site, with the exception of the content of a few directories, to a new domain. After some criticism, we decided that the simplest answer was a RewriteRule in our .htaccess file.

We used the following mod_rewrite rule:

RewriteEngine on
RewriteCond %{REQUEST_URI}!^/test/
RewriteCond %{REQUEST_URI}!^/my-folder/
RewriteRule (.*) http://www.newexampledomain.com/$1 [R=301,L]

This redirects (all the time with a 301 redirect) all site traffic to http://www.newexampledomain.com, with the exception of directory resource requests/test and / my folder. We transfer the user to the exact resource requested using the capture group (. *), Then including $ 1 in the new URL.

Conclusion – Redirect Site Using 301 Redirect In HTAccess

Hope you like the article, How to Redirect an Entire Site Using HTAccess | If you have any problem related to this article tweet us @compsmag or directly contact us on FB/compsmag. You may also use our contact us forum compsmag.com/contact

This is all About – How to Redirect Site Using HTAccess 301 redirect which is the permanent method to move old site to new site without losing your PageRank. If we miss something out then please contact us to make it correct.

Thanks For reading Article;

You may also like – Top 5 Best Paid SEO Tools 2018

Recommended From Our Sister Site – Best CMS (Content Management System) Platforms – For Making a Big or Small site or blog

Compsmag