Setting up a 301 redirect

301 redirects help to solve a number of specific tasks of redirecting traffic and search engine bots from one document to another. There are several ways to implement this feature, but let’s talk about everything in order.

Direct Line
Who are we

Largest agency
Internet marketing outside the Moscow Ring Road:
1200+ projects
65 specialists
fourteen years on the market
TOP 10
the best online promotion companies in Russia 2020

Commercial offer

What is 301 redirect used for?

This type of redirect allows you to set up a permanent redirect from one document to another. After re-indexing the search base, a new page will be shown to users in organic search results.

Reasons for using 301 redirects:

  • The site has changed its domain name, it is being transferred.
  • Specifying site mirrors, for example, with www and without. This is also true in the case of installing SSL certificates.
  • The URL of the page has been changed for the purpose of SEO promotion, for example, keywords have been added to it.
  • Elimination of problems with duplicate pages.
  • Moving the page to a new address, but at the same time it is necessary to maintain its weight and user experience.

301 redirect vs Canonical tag

Before you understand when 301 redirects are used, and in which Canonical tags, you need to understand the key differences between them.

With a 301 redirect, a visitor or crawler is physically redirected. That is, this redirection method is targeted at both bots and humans. The Canonical tag, in turn, is intended exclusively for robots. For example, we have two pages, let’s designate them as 1 and 2, while the second is the main (canonical), and the first is a duplicate (the content of the pages is identical). Our task is to rank the main page in the search results, i.e. the second, but the first should also work. In this case, the Canonical tag comes to the rescue, which allows you to point the search robot to the canonical page.

By the way, if the site contains duplicates, but the Canonical tag is not specified, then the search algorithms will combine them into a group, after which one will be selected, which will appear in the organic search results. The problem is that the choice is often not on the target document.

301 or 302 redirects

Both of these types of redirects physically redirect users and robots to alternative URLs, however, they have significant differences. A 301 redirect informs search crawlers that the page has moved to a new address on a permanent basis. And 302 – for a temporary one, for example, for the period of any promotion.

It is important not to allow confusion in the use of 301 and 302 redirects, otherwise, it will negatively affect the SEO promotion of the page or resource in general.

Where is the 301 redirect set up?

Let’s take a look at the most popular and universal ways of setting up a 301 redirect on a website.

How to set up 301 redirects using Apache server files

Making special edits to the Apache server configuration files is the most common way to set up a 301 redirect. The difference between these files is that httpd.conf is the main server configuration file, and all settings in it affect all directories. And the rules from .htaccess refer exclusively to the directory in which it is located.

The location of the httpd.conf file varies depending on the type of operating system and the version of Apache:

  • FreeBSD (server version 1.3) – /usr/local/etc/apache/httpd.conf.
  • FreeBSD (server version 2.2) – /usr/local/etc/apache22/httpd.conf.
  • Ubuntu (server version 1.3) – /etc/apache/httpd.conf.
  • Ubuntu (server version 2.2) – /etc/apache2/apache2.conf.
  • Linux – /etc/httpd/conf/httpd.conf.

Via plugins in CMS

You can set up 301 redirects not only through configuration files, but also using special plugins for CMS. This option is suitable for users who do not want to understand the server file parameters.


WordPress is the most popular CMS system, so a large number of plugins have been written for it, with which you can set up redirects.


A plugin with wide functionality, tailored exclusively for setting up redirects. Here are some of the functions that are presented in it:

  • Setting up redirects from a 404 error page.
  • Simple redirection from one page to another.
  • Creation of complex redirection rules from several pages to one and so on.
  • The ability to automatically add 301 redirects when deleting or changing pages.

The plugin is completely free, easy to use, and does not affect the server configuration files.

Simple 301 Redirects

Also a simple plugin, but with less rich functionality. The interface is presented in the form of two fields: the URL of the source page and the URL of the page where 301 redirects are configured (exclusive). It is convenient to use when moving a site from one domain to another, or with a small number of pages from which you need to set up 301 redirects. Because there is no possibility of setting up automatic rules; it is impractical to use it for large arrays of addresses.

SEO Redirection

Unlike the previous plugin, SEO Redirection allows you to customize all kinds of redirects, not just 301. Overall, it is a powerful tool with a lot of features, with an average user rating of 4 stars. It is possible to configure automatic rules, as well as view statistics on redirecting individual URLs.

SEO Redirection Plugin
SEO Redirection Plugin

Easy Redirect Manager

The plugin is presented in two versions: paid and free. Contains all the necessary functionality, suitable for both beginners and experienced users.


In the case of Bitrix, setting up a 301 redirect is possible, for example, through the Redirect Master module or by editing the .htaccess file:

RewriteEngine On
RewriteCond %{HTTP_HOST} ^$ [NC]
RewriteRule ^(.*)$$1 [R=301,L]

You can edit the file itself directly through the site admin panel:

Setting up a 301 redirect in Bitrix
Setting up a 301 redirect in Bitrix

Through PHP condition

This ability to customize 301 redirects is more suitable for self-written CMS systems running on PHP. To implement it, you need to add the header () function to the code of the index file (most often index.php) indicating the type of redirect and Location – the site address.

The principle of PHP-based redirects is that the browser requests the index file, then the server reports that it has been moved to another location. After that, the browser sends a request to the specified address, receives a response and displays a new page.

So, let’s go directly to the setup. Example, 301 redirects from one domain to another:

if ($ref!="") $ref="?".$ref;
header("HTTP/1.1 301 Moved Permanently");

Please note that only the new domain is indicated.

Setting up a 301 redirect from one page to another:

header("HTTP/1.1 301 Moved Permanently");

The page to which the redirect is triggered is specified here.

HTML redirect

Suitable for static HTML sites that need to set up a redirect to one or more pages. This method implies adding a special meta tag to the code, let’s analyze the scenarios.

Redirect to another domain:

<meta http-equiv="refresh" content="0;">

Redirect to another page:

<meta http-equiv="refresh" content="0;">

The content parameter is responsible for the delay, a number equal to seconds is specified.

.Htaccess file setup rules for 301 redirects

There are a lot of rules for setting up 301 redirects and they are applied depending on the task at hand. Let’s analyze the most popular ones.

From one page to another

Short version of the option:

Redirect 301 /primer-page1.html/

Expanded version:

RewriteCond %{REQUEST_URI} ^/primer-page1.html/$
RewriteRule ^.*$ [R=301,L]

From home page to catalog

Redirect 301 /

From catalog to home

Redirect 301 /catalog

From one domain to another

RewriteEngine On
RewriteCond %{HTTP_HOST}
RewriteRule (.*)$1 [R=301,L]

301 redirect from http to https

When installing an SSL certificate, a redirect from http to https is configured:

RewriteCond %{HTTPS} !=on
RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R=301,L]

Or an alternative:

RewriteCond %{HTTPS} off
RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

301 redirect from www to non-www

RewriteEngine On
RewriteCond %{HTTP_HOST} ^$ [NC]
RewriteRule ^(.*)$$1 [R=301,L]

From without www to from www

RewriteEngine On
RewriteCond %{HTTP_HOST} ^
RewriteRule (.*) http://www.$1 [R=301,L]

301 redirect for a specific IP address

RewriteEngine On
RewriteCond %{REMOTE_ADDR} 111.222.333.444
RewriteRule ^(.*)$ [R=301,L]

Redirect only from the main page of the site

In this case, 301 redirects will be triggered exclusively when visiting the main page of the site:

RewriteEngine On
RewriteRule ^$ [R=301,L]

Coping with duplicates

Two URLs that are the same, but one has a slash at the end and the other does not. They will be different for search engines, i.e. duplicates. 301 redirects allow you to fight this phenomenon. For example, remove the slash at the end of the address:

RewriteCond %{REQUEST_URI} !?
RewriteCond %{REQUEST_URI} !&
RewriteCond %{REQUEST_URI} !=
RewriteCond %{REQUEST_URI} !.
RewriteCond %{REQUEST_URI} ![^/]$
RewriteRule ^(.*)/$ /$1 [R=301,L]

Change the display of the page extension, for example, from .htm to .html:

RewriteEngine on
RewriteBase /
RewriteRule ^(.*).htm$ $1.html [R=permanent]

Redirect from 404 to home page

ErrorDocument 404

Please note that the mod_rewrite function must be activated using the RewriteEngine on command, but if multiple redirection rules are applied in one .htaccess, then this command is written once.

Memo on the symbols and symbols used

The RewriteCond directive defines the condition for the RewriteRule, if met, the redirect is triggered. Rules are represented as regular expressions.


  • – escape slash, preserves the characters following it in their original form.
  • ^ – the beginning of the line.
  • $ – end of line.
  • ! – negative sign.
  • … – any character.
  • () – used to indicate grouping of characters.
  • # – comments.


Used for ordinary characters, special characters or their groupings. They can be used to change the base values.

  • ? – is placed after a character that may or may not be present. For example, htm? L – both htm and html fall under the rule.
  • * – is placed before a character that can be repeated from 0 (completely absent) to 65536 times. For example, htm * l, the rule includes htm, html, htmm.
  • + – similar to the previous one, but the character can be repeated from 1 to 65536 times.


Specified in square brackets, separated by commas, represent additional options.

  • NC (nocase) – if the rule is triggered, the case does not matter.
  • R (redirect) – terminates the conversion process, returns a response to the browser in the form of a redirect.
  • L (last) – this link is final, and the conversion process stops.

How to check 301 redirects?

To check a single page, just go to it and visually evaluate the redirection process. In other words, if, when entering the page, a redirect to another document occurred, the site address in the browser line changed, then everything is configured correctly. However, it will not be possible to find out what type of redirect worked. It also makes it harder to check the page array. In this case, you will need software or specialized services:

  • is a service that allows you to get the HTTP header of a page.
  • Screaming Frog SEO is a paid program that allows you to crawl your site and find redirects.

So, we examined in detail the question of how to make a 301 redirect, and showed the most universal ways. We hope the article was useful to you.

# seo
# Web development

Leave a Reply

Your email address will not be published.