There are multiple ways to make a 301 redirect from one part of your website to another. By far the best way is to use the .htaccess configuration file. The 301 Redirect is a permanent redirection from one URL to another. Such redirections are useful for SEO, and other reasons but your reason to permanently redirect one URL to another is up to you.
NB! Although it is called a permanent redirect, you can always reverse it, by removing the instructions from your .htaccess file. Yet it is important to note that if a page was 301 redirected, Google and other search engines will accept it as permanent. Therefore, it will be a lot harder to rank the same URL once it was associated to another via a permanent redirect.
How to Make a 301 Redirect
To make a 301 permanent redirect using the .htaccess configuration file, naturally, the first thing you need to do is to access the file. Go to the root directory of your website with our file manager or using an FTP.
Related:
If the .htaccess file does not exist, create a new file and name it .htaccess
.
Now that you have created an .htaccess configuration file, simply open the file with any text editor, and add the lines that are needed to make the redirect. Before we go to the lines, we ought to remind you that you can edit the .htaccess file in the hosting control panel. There is no need to download the file, or any additional software.
301 Redirect for a Single Page
To redirect a single page, use the following syntax:
Redirect 301 /old-page.html http://www.yourwebsite.com/new-page.html
Replace
/old-page.html
with the path to the old page. Replacehttp://www.yourwebsite.com/new-page.html
with the full URL of the new page.
301 Redirect an Entire Domain
To redirect an entire domain to a new domain, use the following syntax:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^old-domain.com [NC,OR]
RewriteCond %{HTTP_HOST} ^www.old-domain.com [NC]
RewriteRule ^(.*)$ http://www.new-domain.com/$1 [L,R=301,NC]
Replace
old-domain.com
with your old domain name. Replacehttp://www.new-domain.com
with your new domain name.
Redirecting All Pages to a New Domain
To redirect all pages from an old domain to the corresponding pages on a new domain:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^old-domain.com$ [NC]
RewriteRule ^(.*)$ http://new-domain.com/$1 [R=301,L]
Replace
old-domain.com
with your old domain name. Replacenew-domain.com
with your new domain name.
After you’ve made the necessary adjustments to your .htaccess file, don’t forget to save it. Either upload the file back to the website’s root directory, or if you edited it in the control panel, click the save button.
What is left for you to do is to test whether the redirects are working as intended and whether the website is working as it was before.
Example
If you want to redirect http://www.yourwebsite.com/old-page.html
to http://www.yourwebsite.com/new-page.html
, your .htaccess file should look like this:
RewriteEngine On
Redirect 301 /old-page.html http://www.yourwebsite.com/new-page.html