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

How to Log in to Elgg

After you install Elgg, it is time to log in to the CMS, so you can start working on your Elgg website. To log in, you should load the Elgg login page and type in your credentials to access the platform’s admin dashboard. In the following paragraphs, we share how to...

How to Install Elgg

You can quickly install Elgg with any of the AwardSpace web hosting plans. You can use our free web hosting, shared web hosting, or advanced hosting plans such as semi-dedicated hosting and VPS hosting.   How to Install Elgg To install Elgg, you should first sign...

How to Change the PHP Timezone

Setting the correct timezone in PHP is crucial for ensuring that date and time functions in your scripts operate accurately. AwardSpace offers a range of hosting plans that provide easy management of PHP settings, including timezone configuration. This article will...



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

How to Log in to Elgg

After you install Elgg, it is time to log in to the CMS, so you can start working on your Elgg website. To log in, you should load the Elgg login page and type in your credentials to access the platform’s admin dashboard. In the following paragraphs, we share how to...

How to Install Elgg

You can quickly install Elgg with any of the AwardSpace web hosting plans. You can use our free web hosting, shared web hosting, or advanced hosting plans such as semi-dedicated hosting and VPS hosting.   How to Install Elgg To install Elgg, you should first sign...

How to Change the PHP Timezone

Setting the correct timezone in PHP is crucial for ensuring that date and time functions in your scripts operate accurately. AwardSpace offers a range of hosting plans that provide easy management of PHP settings, including timezone configuration. This article will...

How to Disable PHP Error Messages

When running a PHP-based website in a production environment, it's crucial to disable PHP error messages to prevent sensitive information from being exposed to users. AwardSpace offers a variety of hosting plans tailored to different needs, all of which support...

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.