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 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...

How to Log In to MediaWiki

After you install MediaWiki, it is time to log in to the platform, so you can start working on your new MediaWiki website. To log in, you must open the MediaWiki login page and enter your credentials. Doing so will open the platform’s admin panel. In the following...

How to Install MediaWiki

You can quickly install MediaWiki on any of the AwardSpace web hosting plans. This includes our free web hosting, shared hosting, as well as advanced services such as semi-dedicated hosting and VPS hosting. You can install MediaWiki in a matter of minutes, whichever...



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 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...

How to Log In to MediaWiki

After you install MediaWiki, it is time to log in to the platform, so you can start working on your new MediaWiki website. To log in, you must open the MediaWiki login page and enter your credentials. Doing so will open the platform’s admin panel. In the following...

How to Install MediaWiki

You can quickly install MediaWiki on any of the AwardSpace web hosting plans. This includes our free web hosting, shared hosting, as well as advanced services such as semi-dedicated hosting and VPS hosting. You can install MediaWiki in a matter of minutes, whichever...

How to Install an Elgg Theme

After you have installed Elgg core and logged in to the admin dashboard, you can search for themes that can help you customize your new website. Elgg themes are a set of files that help you customize the appearance of your website. Via themes, you can modify website...

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.