How to use 301 redirect and 302 redirect

In the life of an SEO, it necessarily becomes a point to fix the missing URLs error such as 404 errors to make it more readable, both for engines and users. We must fight more or less with the .htaccess file located at the root of the site or within a folder.

Today we will therefore look at the file as a bit barbaric but so useful.

The .htaccess file, what is it?

This is a file that gives instructions to the server, it shows commands to follow. In practice, it is thanks to him that we can protect our pages with passwords or we can manage the different error pages (404, 401, 403, etc.). It also allows redirection of pages and URL rewriting. Today I am here to tell you about the redirection, whether permanent or temporary.

For information, This file is called .htaccess, we can not open access any site from our browser for security reasons. .htaccess file is always placed in your server and has a hidden attribute, so if you want to access it you have to select show hidden files. You may download it, edit it and replace it with the earlier one on the server.

301-302 redirect

The 301 redirect

The so-called permanent redirection is used mostly in a site redesign when some pages are moved or deleted. 301 redirect will resolve the 404 error (page not found) and also retain the link juice made to this page.

The 301 redirects can be done with plain text (no coding is required).

The method with text is the easiest to achieve. Clearly, we tell .htaccess to file what to command, let's have a look:

RedirectPermanent /old-page.html

RedirectPermanent /folder/

RedirectPermanent /

How these examples work:

  • The first line allows you to redirect a single page
  • The second line redirects a complete (with its subfolders and pages)
  • The third line allows you to redirect a complete domain to a new domain

Note: Do not forget to make a space after the “RedirectPermanent” and before the final URL.

The 302 redirect

302 redirect is used for temporary redirection which is rarely used. It can be when you edit a page directly online and you do not want the user to see the work or when you, for example, marketing on your site. Google understands that the redirection is not definitive, it does not give the weight of the links to the new page.

Like a 301, a temporary redirect can be done with text or regular expressions. Again you will see only the version with text only. And the method is the same as before, we’ll just change what they say to the server (a temporary redirect and not a permanent redirect).

Redirect /old-page.html

Redirect /old-folder

Redirect /

There may be no need for me to explain the effects of this redirection.. you already know that.

Post a Comment

Previous Post Next Post