What are 301 redirects for? How can I introduce them? What is its correct syntax? If you are asking yourself some of these questions, this is the complete manual you have been looking for.
The 301 redirect is a very useful tool. If you have one or more web sites, and you like to do things right, sooner or later you will have to use this protocol. Often it is a question of hygiene, or information structure. But the truth is that redirects play a vital role in SEO. Let’s go by parts…
Índice de contenidos
What is a 301 redirect?
It is a protocol used to send users from one URL to another, and tells search engine bots to only consider the URL to which they are redirected. 301 redirects are also permanent (not to be confused with temporary redirects, which are performed with 302).
When you want to delete or move a domain or a page, placing a 301 avoids the appearance of the famous 404 error, something that can lead users to be left with a bad impression, or even to believe that the entire domain has been abandoned.
From the point of view of SEO positioning, 301 redirects will also allow us to keep all the link juice, all the strength achieved through links, if we want to move a page or a domain. But again we run the risk of rushing, or being inconsiderate to readers who are less well versed in these matters, so let’s take it one step at a time.
When may I need a 301 redirect?
As I said, if the lifetime of a website is long enough, redirects are inevitable to solve some problems. These are some of the most common cases.
- Establish a canonical version of the web page (with or without www, for example).
- Migrate the domain.
- Make changes to URLs.
- Delete pages permanently.
- Change CMS.
Let’s see now what is the easiest way to introduce 301 redirects to solve the most common problems faced by webmasters.
How to perform 301 redirects with the .htaccess file
The most common, and easiest, way to make redirects is to make certain changes to the .htaccess file, provided you have an Apache server. This requires FTP access. It is something very simple that does not require specialized knowledge, and that anyone can do. To make the task easier, it is best to download FileZilla, an FTP client that will allow you to access your server and make changes in an intuitive way.
FileZilla has an interface with a split screen. On the left side are the folders of the computer, and on the right side are the files hosted on the server. This will allow you to easily upload and download files.
As you can see at the top of the screenshot, to connect FileZilla to your server you must enter the hosting name, the username and the corresponding password. If you do not have any of this information, you should contact your hosting provider to get it. The port is normally 21.
Once you have connected to your server via FTP, you must locate the .htaccess file, in the files on the right side of the screen. As you can see in this screenshot.
Once you have found the .htaccess file just click on it with the right mouse button to open a drop-down menu with the options to perform. Select “view/edit”, and copy the content to notepad to save a backup copy (any change in the .htaccess file can cause serious problems). Then you only need to add the lines of code to implement the 301 redirects.
Let’s see now what you need to enter in .htaccess, depending on the type of redirects you need to perform.
Redirect a domain
If you need to redirect your domain, because it is no longer search engine friendly, or for any other reason, you can enter the following code:
Redirect 301 /http://www.nuevodominio.com/
But it is very likely that you want to move all the content of your old domain to the new one, in which case you will have to write the following:
RedirectMatch 301 ^(.*)$ http://nuevodominio.com/
This will ensure that the pages with the old domain are moved to the new one respecting the original structure.
Redirect a page
If you want to redirect a specific page, or a few pages, you can do it like this:
Redirect 301 /antigua-pagina http://dominio.com/nueva-pagina
Delete a page
As we said at the beginning, to prevent the user from encountering a 404 error when deleting a page, you can use redirects, send them to another site and prevent them from escaping to a competitor’s website. 301s are very useful for e-commerce, where the different product offerings available may mean that pages need to be deleted frequently. You can, for example, redirect the user to the category to which the deleted product belongs, in case he/she wants to purchase another related item.
In this case, the redirection is very similar to the one used in the previous point:
Redirect 301 /categoría/producto/ http://dominio.com/categoría/
Directory redirection
To move a directory keeping all internal pages included in the root,
Redirect 301 /antiguo-directorio/ http://dominio.com/nuevo-directorio/
And you can do the same with subdirectories. You can add or remove levels in directories and subdirectories, following the same syntax. It’s very simple!
Tips
As you have seen, working with redirects is not too complicated, although you should keep in mind some recommendations:
- Remember to make a copy before editing the .htaccess file.
- Your Apache server must have the
mod_rewrite
enabled. Therefore, you must add in the .htaccess, before writing the commands with the redirects, the following:
Options +FollowSymlinks RewriteEngine on
- If it is a migration, including a change of hosting, do not forget to keep the web hosting of your old domain active for a few months, with the Sitemap, so that the bots can follow the redirects.
And finally, if you do not see it clearly, go to professionals. In some cases, small jobs like the ones we have explained here, relatively easy, become complicated. You decide! 🙂
Sin asignación particular. Artículos redactados por el el equipo de Rodanet. Varias personas del equipo participan en crear los mejores artículos en cooperación y equipo 💪 Porque nos encanta trabajar en equipo 🔝