How to make a redirect: a detailed overview

In this article, you will find detailed information about redirects. Get to know the types of redirects and find out what tasks they solve. Learn how to redirect in different ways and which redirect method is preferable in specific cases.


What are redirects and why are they needed

Redirect - redirecting a user from one URL to another. For example, when clicking on the link, the browser automatically redirects the user to the URL

Redirects help to correctly redirect visitors to the desired pages on the site without compromising user experience and without violating the requirements of search engines. A correctly executed redirect preserves the authority or link weight of the donor page and transfers it to the acceptor page. In this case, the donor is the page from which the users are redirected. Acceptor - the page to which users are directed.


Here are some examples of using redirects:

  • Redirect from http to https.
  • Redirecting a URL from www to a non-www URL and vice versa.
  • Moving a site to another domain.
  • Redirecting traffic from one page of the site to another. For example, if an online store does not have a product, it can redirect traffic to a page of a similar product.
  • Redirecting users to the mobile version of the site. If the resource owner uses only the mobile version of the site to adapt to mobile traffic, he configures a redirect for mobile users.

With the help of redirects, the site owner directs users from irrelevant pages to relevant ones. Redirects are classified by functionality and implementation.


What are the types of redirects and when they are used

For the user, all redirects are the same: when they try to go to one URL, they go to another URL. Usually, Internet surfers don't even notice that the browser has redirected them from one address to another.

Browsers and search engine robots determine the type of redirect based on the HTTP status code. Redirects can have different HTTP status: 301, 302, 303, 307. Let's take a closer look at each one.


Redirect 301

This is the most common type of redirect. HTTP status 301 means that the resource has been permanently moved from the requested URL to the new one. After receiving a 301 response, the browser makes a new request and redirects the user to the current page.

If you use a 301 redirect, the authority and link profile of the old page is transferred to the new one. For example, don't be afraid to lose the weight of incoming links when you move your site to a secure connection protocol. A correct 301 redirect from http to https preserves this characteristic of the resource and its specific pages.


Redirect 302

In HTTP 1.0, the 302 status was used to indicate the temporary movement of the requested resource to a new address. In HTTP 1.1, a 302 redirect indicates a Found status. That is, the resource exists, but the owner moved it to a new address for some time. The 302 redirect does not convey the donor's authority and link profile to the acceptor.

In HTTP 1.1, 303 and 307 redirects are proposed for temporary redirects. This is due to incorrect handling of the 302 status in some browsers.

According to HTTP 1.0 standards, the browser must use the POST method for a new request after receiving a 302 response. Some browser developers do not adhere to this standard and use the GET method for a new request. In HTTP 1.1. redirects 303 and 307 solve this problem.

Instead of 302 for temporary redirects, it is better to use 303 and 307 redirects.


303 and 307 redirects

In HTTP 1.1, the 303 status was proposed instead of the 302 redirect. The meaning of the code is See Other. The browser must use the GET method for a new request. Use a 303 redirect when you do not have an adequate response to the user's request, but there is a more or less suitable replacement.

A 303 redirect is fine when there are forms on the landing page. In this case, it is important that the browser makes the request with a secure GET method.

The 307 status is also used instead of the 302 redirect. The code value is a Temporary Redirect. The browser should not change the new request method. Safe GET and HEAD requests are made automatically. Unsafe requests such as POST are made with user confirmation.

Use a 307 redirect to indicate that the resource you are looking for is temporarily available at a different address.


Intermediate conclusion: in most cases, a 301 redirect is suitable for site owners. In this case, the HTTP status notifies search robots that the document has been permanently moved to a new address. This type of redirect transfers authority and link mass from the donor page to the acceptor page. Redirects 303 and 307 are used when the site owner wants to temporarily redirect users from one document to another.


What types of redirects exist

Redirects are classified according to the way they are implemented. You can configure redirection through the .htaccess file or nginx.config, using PHP, HTML, JavaScript. More on each type below.


What is htaccess redirect

To set up redirection, edit your .htaccess file. Use an FTP client to access the file. The .htaccess file is located in the folder with the name of the resource domain name in the public_html directory.

htaccess redirect using FTP


You can also access the .htaccess file through your hosting control panel. In cPanel, open the "Files - File Manager" section of the interface.

htaccess redirect using Cpanel


PHP redirects

PHP redirect works at the server level. This method of redirection is considered less preferable than redirecting through the .htaccess file, as it is slower. But in some cases it is preferable to use this type of redirect.

For example, if your site has dozens of pages for which you need to register a redirect, as well as dozens of pages for which a redirect is not needed, it is better to set up redirects using PHP.

Download the index.php file to your hard drive or open it for editing in the file manager of the hosting control panel. The file is located in the root folder of the site. .htaccess file is also located there.


JavaScript redirect

A JavaScript redirect is done on the browser side, not on the server side. For the visitor to get from the old page to the new one, the redirect script must be fully loaded in the browser. Therefore, JavaScript redirects are slower than server-side redirects. Another problem is that automatic redirection will not work if the user has disabled JavaScript in the browser.

However, JavaScript redirects are convenient in some cases. For example, they can be used for delayed redirection. You can write on the old page a message like "We have moved to the new site, now you will be automatically redirected there." After a few seconds, the user will automatically be taken to a new page.

To implement a JavaScript redirect, add a redirect code between the <head> and </head> tags of the page you want to redirect users from. On WordPress sites, this can be done using the free Per page add to head plugin.


HTML redirect

This type of redirect also works on the browser side. For the redirect to work, the browser must load the appropriate HTML: the refresh meta tag. Therefore, this type of redirect is slower than server-level redirects.

To implement a redirect, add code between the <head> and </head> tags of the page from which you want to redirect traffic.

Subtotal: Prefer server-side redirects as they are more user-friendly. In most cases, redirection is best configured through the .htaccess configuration file for Apache servers and nginx.config for Nginx servers.


Where to get the redirect code

If you do not have the appropriate experience and knowledge, you have two options. You can contact our specialists or use the online code generator. A selection of services below will save you time and money:

301 Redirect Code Generator. Generates redirect code for Apache, ASP and ASP.NET. Also generates JavaScript and HTML redirects.
Seomagnifier. Creates a 301 redirect code from the www domain to the non-www domain and vice versa.
301 Redirect Code Generator Tool. Creates redirects from page to page, as well as from a domain without www to a domain with www. Generates PHP code, redirects for ASP and ASP.NET servers, HTML and JavaScript redirects.
Htaccess file generator. Creates a code of redirects from page to page, as well as between sections of the site, generates redirection scripts from a domain from www to a domain without www.
Generic redirect code generator for .htaccess. You can choose a redirect script, specify a URL and generate a code.
Generator of redirects 301. Generates redirection code for servers on Apache, ASP, ASP.NET, as well as HTML and JavaScript redirects.
Brontobytes redirect generator. It will help you set up a redirect from the old domain to a new one, change the address of individual pages and sections of the resource, set up a redirect from a domain without www to a domain with www.
- Nginx server users will find the code converter useful. It transforms .htaccess redirects to nginx.config redirects.

How to redirect: examples

This block contains the most popular redirects. The instructions will help you set up redirects by yourself.


How to redirect from http to https

Often, site owners are faced with the need to make a server redirect when transferring a site to a secure connection protocol. To implement a redirect, follow these steps:

1. Download the configuration file to your hard drive or open it for editing in the hosting control panel.
2. Generate a redirect code using one of the above services.
3. Add the code to the file, save changes and upload the .htaccess to the server.  


How to redirect from or to www

For detailed instructions on redirecting from a non-www domain to a www domain using the .htaccess file, see the article on site mirrors. If you want, do the same redirect with php. Proceed like this:
1. Download the index.php file to your hard drive.
2. Generate the redirect code.
3. Paste the code into the file, save the changes and upload index.php to the server.
4. Specify the main URL in the site settings. In WordPress, this can be done in the Settings - General menu.


How to set up a redirection from one page

To set up a redirect from one page to another, edit the .htaccess or index.php file: add the generated redirect code to it.


How to set up a redirect when changing a domain

When moving to a new domain, redirection is configured in the same way as redirects from http to https or from a domain from www to a domain without www. Changes can be made via the .htaccess or index.php file.


How to check a redirect

You can check the redirect in your browser. Clear your cache or open your browser in incognito mode and enter the desired URL. You can also check redirects using web services:

Redirect Checker

Redirect Check

Checkers show the type of redirect and the server response status when switching to a new address.

Checkers show the type of redirect and the server response status when switching to a new address.


It's easy to make a redirect

To do this, first of all, select the type of redirect. In most cases, a 301 redirect or permanent redirect is fine. Sometimes it is worth using 303 and 307 redirects for temporary redirects.

Then select the type of redirect. Server redirects are the fastest, which are configured using .htaccess configuration files for Apache servers and nginx.config for Nginx servers. You can also set up a PHP redirect using the index.php file. JavaScript and HTML redirects are slower, so use them in exceptional cases.

Generate a redirect code using one of the services suggested in the article and add it to the configuration file or to the index.php file. Check the correctness of the redirect manually or using a web service.


Well, if you want to entrust the work on redirects to a professional SEO team, we will be happy to help you!



Leave Your comment and receive Backlinks

You must log in! Log in

More than 10 years in the game and we're just getting started.