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 Find Modules in MediaWiki

After you install MediaWiki, log in to the CMS, and presumably install extensions, it is time to learn how to find modules in MediaWiki.   What are MediaWiki Modules Modules in MediaWiki are Lua-based scripts that allow you to add various functionalities to your...

How to Fix MediaWiki Internal Error: A Step-By-Step Guide

MediaWiki Internal Error message can be very frustrating and can significantly harm your MediaWiki project. Luckily, the issue can be fixed in a few easy-to-follow steps to get your website up and running in no time. There are various causes for the issue: Incorrect...

How to Add Infobox Module in MediaWiki

The Infobox in MediaWiki is a handy tool for presenting content and key information in a structured and visually pleasing way. Infoboxes are useful for any kind of MediaWiki project and can provide your readers with a quick snapshot of important data and details. In...

How to Install a MediaWiki Skin

In MediaWiki, skins determine the visual appearance of your wiki website. Skins define how content is presented to users and include such settings for the overall website layout, typography, color scheme, and more. By default, when you install MediaWiki, the platform...

How to Create a Page in MediaWiki

Creating pages in MediaWiki is а core feature that allows you to add content to your MediaWiki website. Whether you are adding details for a project, contributing to a knowledge base, or anything else, learning how to create a page in MediaWiki is crucial for your...



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 Find Modules in MediaWiki

After you install MediaWiki, log in to the CMS, and presumably install extensions, it is time to learn how to find modules in MediaWiki.   What are MediaWiki Modules Modules in MediaWiki are Lua-based scripts that allow you to add various functionalities to your...

How to Fix MediaWiki Internal Error: A Step-By-Step Guide

MediaWiki Internal Error message can be very frustrating and can significantly harm your MediaWiki project. Luckily, the issue can be fixed in a few easy-to-follow steps to get your website up and running in no time. There are various causes for the issue: Incorrect...

How to Add Infobox Module in MediaWiki

The Infobox in MediaWiki is a handy tool for presenting content and key information in a structured and visually pleasing way. Infoboxes are useful for any kind of MediaWiki project and can provide your readers with a quick snapshot of important data and details. In...

How to Install a MediaWiki Skin

In MediaWiki, skins determine the visual appearance of your wiki website. Skins define how content is presented to users and include such settings for the overall website layout, typography, color scheme, and more. By default, when you install MediaWiki, the platform...

How to Create a Page in MediaWiki

Creating pages in MediaWiki is а core feature that allows you to add content to your MediaWiki website. Whether you are adding details for a project, contributing to a knowledge base, or anything else, learning how to create a page in MediaWiki is crucial for your...

How to Install MediaWiki Extensions

Now that you have installed MediaWiki and learned how to log in to the CMS, it is time to extend MediaWiki's functionality via extensions. MediaWiki extensions are sets of files that add various types of functionality to your MediaWiki website. You can use extensions...

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.