How to Make a 301 Redirect Using .htaccess

Home » Knowledge Base » Website Management – Advanced » .htaccess » How to Make a 301 Redirect Using .htaccess

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. Replace http://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. Replace http://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. Replace new-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

 

Was this post helpful?

i

Relevant tags:

Connect

Latest posts:

How to Remove a Product in OpenCart

After installing OpenCart and logging in to the dashboard, you can start adding and removing products immediately. We have already covered how to add products in OpenCart, and in this article, we share simple steps to delete products from your store with only a few...

How to Add Products in OpenCart

The most important element in your OpenCart project is the products you will offer your site visitors. In the following paragraphs, we share how to add products to your OpenCart website.   How to Create Products in Opencart The process of adding new products in...

How to Log in to OpenCart

After you install OpenCart, you can log in to the platform and start working on your project right away. To log in, you should open the OpenCart login page and enter the credentials you chose when installing the CMS. This will open the platform’s admin panel. In the...

How to Install OpenCart

You can install OpenCart on every AwardSpace web hosting plan, including our free web hosting, shared hosting, and advanced AwardSpace services such as Semi-Dedicated Hosting and VPS hosting. Keep in mind that all of the AwardSpace hosting services are tailored to run...

How to Change My Last Name in Moodle

If you are asking yourself "How to change my last name in Moodle", then you are at the right place. This guide will walk you through the steps for changing your last name in Moodle while addressing common concerns like ratings and discussions.   How to Change My...



Create a website for free!


Free forever

Our Support Team is Here to Help

 

If you need any questions answered, don't hesitate and contact us. Click the button below and follow the instructions. You can expect an answer within an hour.

 

Contact AwardSpace

 

iNewest knowledge base articles

How to Remove a Product in OpenCart

After installing OpenCart and logging in to the dashboard, you can start adding and removing products immediately. We have already covered how to add products in OpenCart, and in this article, we share simple steps to delete products from your store with only a few...

How to Add Products in OpenCart

The most important element in your OpenCart project is the products you will offer your site visitors. In the following paragraphs, we share how to add products to your OpenCart website.   How to Create Products in Opencart The process of adding new products in...

How to Log in to OpenCart

After you install OpenCart, you can log in to the platform and start working on your project right away. To log in, you should open the OpenCart login page and enter the credentials you chose when installing the CMS. This will open the platform’s admin panel. In the...

How to Install OpenCart

You can install OpenCart on every AwardSpace web hosting plan, including our free web hosting, shared hosting, and advanced AwardSpace services such as Semi-Dedicated Hosting and VPS hosting. Keep in mind that all of the AwardSpace hosting services are tailored to run...

How to Change My Last Name in Moodle

If you are asking yourself "How to change my last name in Moodle", then you are at the right place. This guide will walk you through the steps for changing your last name in Moodle while addressing common concerns like ratings and discussions.   How to Change My...

How to Change Your Name in Moodle

Changing your name in Moodle is a very simple task and requires only a few minutes of your time.   How to Change My Name in Moodle The process is comprised of a few easy-to-follow steps:   Step 1: Log in to Moodle After installing the CMS, you should log in...

Even more web tutorials

Check out our web hosting knowledge base and the WordPress tutorials to learn more, and be better prepared for your website creation and maintenance journey.