Redirect – what is it and how to set it up?

Redirect – what is it and how to set it up?
Redirect – what is it and how to set it up?

Redirecting is the process of automatically redirecting a user from one URL to another, which is useful when changing the URL of a page, moving a site to another domain, fixing URL errors, ensuring site security, etc. A redirect can be done at the web server level when it receives a request from the user, or at the page code level when the web page script makes a request to redirect the user.

Forwarding Methods

Depending on the purpose of redirection, various redirection methods are used, each of which has its own characteristics.

  1. Redirect is a method that automatically redirects the user from one URL to another. There are different types in redirects such as 301, 302, 307, etc., indicating different types of redirects.
  2. Meta Refresh – Uses the HTML <meta> tag to automatically redirect the user to a new page. This can be useful, for example, when automatically refreshing a page after a certain time. However, this method has some disadvantages such as inconvenience for users and worse SEO as search engines may perceive it as a scam.
  3. JavaScript Redirect – This method uses JavaScript to redirect the user to another URL. This method can be useful for redirecting a user after filling out a form or after performing certain actions on a page, but may be blocked by browsers for security reasons.
  4. Canonical Links – An HTML tag that points search bots to the main URL of a page that should be indexed by search engines. Canonical links can be useful when a site has duplicate pages with different URLs, and can help avoid duplicate content and improve SEO.

Let’s take a closer look at the Redirect method, which is important for search engine optimization in terms of maintaining page weight and position, and therefore organic traffic.

Types of redirects

There are several redirection statuses codes in the HTTP protocol that describe the redirection status from the server to the client:

  • 301 Moved Permanently – This code means that the resource has been moved to a new URL and the corresponding URL no longer exists, used for permanent moves. The authority and position of the donor page are transferred to the acceptor page, which will be present in the search engine index.
  • 302 Found – means that the resource has been temporarily moved to a new URL, and the corresponding URL may reappear in the future. Consequently, the new URL will not be indexed, and search metrics and settings will remain at the “old” address.
  • 303 See Other – This code means that the client should go to another URL that the server specified. It is used to return POST or PUT requests.
  • 304 Not Modified – This code is returned when the resource has not been modified since the last request, meaning the client can use a cached version of the resource.
  • 307 Temporary Redirect – This code is similar to 302, but the HTTP request method that was used at the time of the original request is retained. Only used when the client must use the same HTTP request method to make a second request.
  • 308 Permanent Redirect – This code is similar to 301, but preserves the HTTP request method that was used on the first request. It should only be used when the client must use the same HTTP request method to make a second request.

More detailed information regarding 3xx server response codes is provided in the article – Response codes 3xx.

Examples of using 301 redirects in .htaccess

Let’s look at the most common cases of using 301 redirects with examples of implementation in the .htaccess configuration file, which can be found using FTP or through hosting services.

Note: making changes to .htaccess can lead to errors in the operation of your site, so if you do not have enough experience, it would be better to turn to professionals.

301 redirect from the old page URL to the new one

If you need to change the address or delete an indexed page, using a 301 redirect will help maintain its position and weight

Redirect 301 /old_url_addr /new_url_addr

301 redirect from one domain to another

Rule for setting up redirection of all pages of the old domain to the new one, while maintaining the site structure:

Redirect 301 / https://new-sitename.com/

This redirect is used when transferring a website to a new domain, but you can find a complete list of actions for a “successful” transfer in our article “Website transfer without losing positions”.

301 redirect from HTTP to HTTPs

By installing an SSL certificate, you will receive a secure version of the site (using the https:// protocol), but the unprotected version (using the http:// protocol) will also remain available. To “glue” you need to configure a 301 redirect from HTTP to HTTPs – add the following rule to .htaccess:

RewriteCond %{HTTPS} !=on

RewriteRule ^(.*)$ https://sitename.com/$1 [R=301,L]

301 redirect of uppercase characters to lowercase

Links with uppercase and lowercase characters (https://sitename.com/blog and https://sitename.com/Blog) are perceived by search bots as links to different pages, so it is useful to set up a redirection to the main version. Settings using .htaccess and PHP:

Add code to .htaccess:

RewriteCond %{REQUEST_URI} [AZ][OR]

RewriteCond %{QUERY_STRING}[AZ]

RewriteCond %{REQUEST_FILENAME} !-s

RewriteRule (.*) rewrite-strtolower.php?rewrite-strtolower-url=$1 [QSA,L]

Create a file in the same directory rewrite-strtolower.php with the lines:

<?php

if(isset($_GET['rewrite-strtolower-url'])) {

$url = $_GET['rewrite-strtolower-url'];

unset($_GET['rewrite-strtolower-url']);

$params = http_build_query($_GET);

if(strlen($params)) {

$params = '?' . $params;

}

header('Location: https://' . $_SERVER['HTTP_HOST'] . '/' . strtolower($url) . $params, true, 301);

exit;

}

header("HTTP/1.0 404 Not Found");

die('Unable to convert the URL to lowercase. You must supply a URL to work upon.');

301 redirect to URL without extension

For example, you have a page https://sitename.com/help.htm and want a redirect to the URL https://sitename.com/help , add a rule:

RewriteCond %{REQUEST_FILENAME} !-f

RewriteCond %{REQUEST_FILENAME} !-d

RewriteCond %{REQUEST_FILENAME}.htm -f

RewriteRule ^(.+)$ $1.htm [L,QSA]

RewriteCond %{THE_REQUEST} ^[AZ]{3,9}\ /.*\.htm\ HTTP/

RewriteRule ^(.*)\.htm$ /$1 [R=301,L]

By changing .htm to another value, you will get a rule for redirecting the desired extension.

301 redirect to an address without a slash to a slash

Rule in .htaccess for setting up a 301 redirect for links without a slash to the address:

RewriteCond %{REQUEST_FILENAME} !-f

RewriteRule ^(.*)$ /$1/ [L,R=301]

and vice versa, to get links without a slash:

RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule ^(.*)$ /$1 [L,R=301]

301 redirect from WWW without WWW

Pages with WWW in the URL and without WWW are identified by the search engine as duplicates. It is advisable to select one and set up forwarding to it from other options.

If the site has positions, you need to check which version has greater visibility (more pages in search results):

  • use the “site” operator (site:www.sitename.com and site:sitename.com) to determine which option has more pages in the results;
  • check the number of pages in the index using Google Search Console by adding and confirming each of the site mirrors.

To configure a 301 redirect of links without WWW to an address with WWW, add the following code to .htaccess:

RewriteEngine On

RewriteCond %{HTTP_HOST} ^v sitename\.com$ [NC]

RewriteRule ^(.*)$ https://www.sitename.com/$1 [R=301,L]

On the contrary, the rule for setting up a 301 redirect from WWW to an address without WWW:

RewriteEngine On

RewriteCond %{HTTP_HOST} ^www.sitename\.com$ [NC]

RewriteRule ^(.*)$ https://sitename.com/$1 [R=301,L]

You can view a more detailed description of redirect settings in .htaccess at link.

Setting up redirects using CMS

The vast majority of CMSs have a set of tools for setting up redirects; they can be integrated or plugins are used. To use, please read the relevant instructions.

Common errors with 301 redirects

Setting up redirects for a site does not always work correctly, so it requires checking and, if necessary, adjustments. Let’s look at the most common problems that arise when using redirects.

Redirect doesn’t work

For example, you added a rule to .htaccess, but the redirection does not work. The commands in the file may be in the wrong order, try placing the “broken” command at the beginning of the file. In .htaccess, the first directive can modify the request, and it will not satisfy the conditions of subsequent directives.

Redirect chains

Sometimes when you click a link, you don’t get to the final page right away, and instead of one redirect, more are required (for example, from http:// to https:// and then from a WWW to a non-WWW URL). Each of the “extra” redirects is an additional load on the server and an increase in page loading time, which neither search bots nor visitors will like.

Cyclic redirects

This is an error in the logic of setting up redirects, when one page address is redirected to the previous address in the redirect chain and in a circle. The final page will not load and an error “ERR_TOO_MANY_REDIRECTS” will occur.

Broken redirects

If a site visitor or search bot cannot get to the final page of the redirect, the page does not open and returns a 4xx or 5xx server response code. This page cannot appear in search results. It is advisable to periodically check for errors in the wear of redirects on the site. To do this, you can use both Google Search Console by adding your website and application. SEO Spider Screaming Frog.

To summarize

The use of redirects in SEO optimization, when configured correctly, helps maintain and grow the site’s position. Periodically checking the website and eliminating problems with redirects, broken links, etc., helps improve the user experience and quality of site indexing, and therefore increase traffic.

At the same time, incorrect redirect settings lead to deterioration in the quality of search engine optimization and the performance of the web resource in general, and corrections can cost a lot of resources and time. So, in the absence of sufficient experience, we recommend entrusting the redirection settings to experts: programmers and SEO optimizers.

Oleksandr Romanenko
Team Lead/Senior SEO specialist
commercial offer

    SEO promotionCopywritingSMM promotionDevelopmentContextual advertisingDesign
    Digital новини в нашому телеграм-каналі
    Інтернет-маркетинг
    простою мовою
    subscribe
    Other articles by the author
    06/08/2024
    Website layout is the process of creating the structure and appearance of web pages using the HTML markup language, cascading style sheets CSS, and other technologies. It is an important part of web development that ensures the correct display of content on different devices and browsers.

    13/03/2023
    It's a mistake to think that strategy and tactics are the same thing, they have fundamental differences, although they are closely related. Strategy is an overall plan. Tactics are the means used to achieve the goal. It is important to create a strategy with the end goal in mind, as it will take time, effort, and patience.

    02/07/2024
    Google Search Console, also known as GSC, is a free service from Google that allows website owners to monitor the overall health and performance of their sites using data directly from Google.

    Latest articles by #SEO
    24/04/2025
    Usually, SEO specialists use various services such as SEMRush, Serpstat, or Ahrefs to analyze various kinds of data (meta tags, keys, etc.). But all the powerful functionality of these tools is not always appropriate for some small or everyday SEO tasks.

    23/04/2025
    Search query content in SEO is the meaning that a user puts into their query to a search engine. Otherwise, intent can be called the goal, intention, and in some ways even the user's pain.

    01/04/2025
    The iFrame tag is a useful tool for diversifying the content on a website. WEDEX will tell you how the tag affects SEO and what you should pay attention to.

    WhatsApp Telegram Viber Почати розмову