In this guide, I explain how to make 301 redirects and all the types that exist. Then we will move onto the .htaccess file and the codes to do it. Redirects are very useful to fix 404 errors or when you have to migrate from one domain to another, or from one web structure to another.
Before getting into the details and seeing how to apply each of the 301 redirects that exist, you must be clear about some concepts.
For example, you need to know what htaccess is and how it is edited? When is it advisable to make 301 redirects? What precautions to take and a few more things … Let’s move on to it!
What is a 301 redirect?
This is a command with which we direct visitors from one web address to another. Within this concept, we find different types of redirection.
The 301 redirect is nothing more than a permanent command that makes your website to show a specific URL, whenever you want to access a specific URL (the redirected one) it automatically leads to the destination URL.
For example, if you apply a 301 redirect to the website www.example.com/page1 indicating to go to www.example.com/page2, when a user or search robots want to access /page1, they will automatically be directed to /page2.
What is htaccess
The first thing you should know is where its name comes from: Hypertext Access or Access to Hypertext. This is a configuration file used on Apache web servers with which webmasters can configure access policies to directories and files on the web to perform configurations such as redirects. It is a simple text file that you can edit with Notepad or any editor.
How to edit the htaccess file?
In order to make the 301 redirects that we are going to see in this article, you need to know how to access and edit your htaccess file. There are different ways to apply 301 through htaccess.
Watch out! The htaccess file is very delicate, any error in its edition can cause serious errors in the operation of a site.
I recommend that you make a backup of the files prior to any changes. If after making the change, you notice the slightest error on the web, undo the changes you have made or upload the backup you had made.
Be meticulous and check that everything works perfectly.
1. Through FTP: you will find the file by accessing your server through an FTP client. You can use FileZilla for example or any other.
Once you have accessed you can edit the htaccess file with the rules that we will see later.
2. With the SEO Yoast plugin for WordPress: if you have WordPress and have SEO Yoast installed you can also edit the htaccess file.
To do this, from the WordPress admin, in the left sidebar go to SEO -> Tools -> File editor. In ‘File editor’ you will see that you can edit the htaccess. In this section, you can also edit and create the file Robots.txt.
3. Through the file manager of your Hosting: where you can download and upload the file again, or use the online web code editor.
When may you need to do a 301 redirect?
There are many cases, perhaps more than you think, in which you may need a 301. Depending on the purpose of these redirects and their nature (transmit authority, avoid 404 errors, web migration, etc.) there are several cases. Let’s see several examples:
#Example 1: Discontinued products in Ecommerce
Imagine that in your e-commerce you had a well-positioned product, but that for stock reasons you will no longer have it for sale. This product page can be redirected to another page of a similar product.
It is recommended that this landing page is related to the source product, so you will not disappoint the user. Also, the authority that had the source page will go to the destination page. You can send an automated email using free autoresponders to notify about discontinued products in e-commerce. This notification can also be done using a free SMTP server.
#Example 2: URL structure change
We are facing a website that has a link structure that shows the product pages as follows: www.laweb.com/category/producto. The decision is made that the new structure be www.laweb.com/producto, simplifying the URL.
This change will require a 301 redirect, otherwise, pages with the old URL will appear with a 404 error.
#Example 3: Landing pages
Imagine a website that offers products and creates landing pages quite regularly with offers. If the landing pages offer similar offers on similar products, you can choose to redirect from one landing to another in the event that the original one is out of date. In this way, if we have a page with good authority, we will help the new landing page to start with an advantage. You can design a landing page using Sendinblue, here is a complete guide to your Sendinblue review and pricing.
#Example 4: Updating old or expired items
If you have a blog, you may have articles that have an interesting page authority, but because of the content and the age of it, it no longer generates many visits. Something you can do is update that same content, but there is another option.
Create an entirely new article, add the information from that old post, update it, and add new content. Once you publish the new article, perform a 301 redirect from the old article to the new article, this way it will be much easier to position the new one.
#Example 5: Domain changes
Sometimes websites change domain, either because they prefer to be identified with another, for SEO reasons, or even for reasons of changing the brand name.
#Example 6: Content duplicated by www or https
It can occur on all kinds of websites. Unknowingly, your website may have duplicate content, for example, if your website has a version with ‘www’ and without ‘www’ and there is no redirect since both websites offer exactly the same content, we would be talking about duplicate content. This type of duplication can also occur with the HTTP and HTTPS protocol.
Google Panda and penalties
Google Panda is the Google algorithm that was launched in February 2011. Its objective was to combat those websites that offered poor quality content and duplication, that is, copied from other websites. Furthermore, Panda does not welcome the content with less than 300 words.
For Google, the user comes first, and therefore in its search results, it wants to offer them the best content.
If you have duplicate content, both internal and external or you have a lot of content that does not reach 300 words, you can be penalized by Google Panda.
If you’ve already been penalized or want to know if you’re being penalized.
How to detect duplicate content?
Before you start making 301 redirects, it is advisable that you have located the possible duplications on your website or blog. There are different ways to check it, but I recommend a free tool that quickly tells you the percentage of duplicate content and tells you where it is on your website.
The tool in question is called Siteliner, it offers you free analysis of 250 pages. In addition to the duplicate content, it also indicates the broken links it has found on your website.

Types of 301 redirects and how to do them
Requirements: for the redirects you make on the htaccess to work correctly, it is necessary that the ‘Mod rewrite’ is activated, also the webserver must be Apache. To find out if the rewrite mod is activated, search your htaccess file for this command: RewriteEngine On.
- From www to without www version. It may be the case that there are two versions of your website, one with ‘www’ (www.wpoven.com) or without ‘www’ (wpoven.com). If your website has these two versions, we are dealing with duplicate content.
You can check if your website has both versions or if one redirects to another. To do this, search your browser for both versions, if instead of redirecting from one version to another automatically, both offer the same content, you need to do a 301 redirect.
If you want to redirect from a version without www to a version with www , you must use this rule in htaccess:
<IfModule mod_rewrite.c> RewriteCond% {HTTP_HOST} ^ example.com [NC] RewriteRule (. *) Https://www.example.com/ $ 1 [R = 301, L, QSA] </IfModule>
If you want to redirect from a version with www to one without www:
<IfModule mod_rewrite.c> RewriteCond% {HTTP_HOST} ^ www.example.com [NC] RewriteRule (. *) Http://example.com/ $ 1 [R = 301, L, QSA] </IfModule>
- From http to https / from https to http. If you have a website and have just installed the SSL certificate, it is convenient that your entire website is shown with https. For this you must include in your htacces this rule:
<IfModule mod_rewrite.c> RewriteCond% {HTTPS} off RewriteRule (. *) Https://www.example.com/ $ 1 [R = 301, L, QSA] </IfModule>
If on the contrary, you had your website under the https protocol but you have decided to remove it, you must redirect to your website in http version. To do this, enter:
<IfModule mod_rewrite.c> RewriteCond% {HTTPS} on RewriteRule (. *) Http://www.example.com/ $ 1 [R = 301, L, QSA] </IfModule>
What is https
Unlike HTTP, the https protocol offers greater integrity, confidentiality and, consequently, more security. This allows it to be used on websites such as e-commerce, to carry out transactions safely. For the connection to be secure, a digital certificate or SSL certificate is required.
What is an SSL certificate?
- Index / Home. This is a duplication that occurs on many websites and can be solved with a 301 redirect. For example, the websites www.example.com/index.html and www.example.com/home show the same content, keeping the URL as is www.example.com. The first two websites with /index.html and / home should automatically redirect to www.example.com.
To do this, in the htacces we will indicate the following rule:
Redirect 301 /index.html http://example.com Redirect 301 / home http://example.com
Remember: the URL that you want to be redirected must be indicated as a relative URL, that is, / laURL.
- With / to without /. Perhaps it is something you have never checked but you may have both options enabled on your website. If your website is visible with the slash (/) at the end and also without it, we are facing a duplication that you can solve by applying the following rule:
To redirect from the version with bar to the version without bar:
<IfModule mod_rewrite.c> RewriteCond% {REQUEST_FILENAME}! -F RewriteCond% {REQUEST_URI}! (. *) / $ RewriteRule (. *) Http://www.example.com/ $ 1 / [R = 301, L, QSA] </IfModule>
To do the opposite:
<IfModule mod_rewrite.c> RewriteCond% {REQUEST_FILENAME}! -D RewriteRule (. *) / $ Http://www.example.com/ $ 1 [R = 301, L, QSA] </IfModule>
- Page redirection. This is quite simple and can be used to direct from any page to another destination.
Redirect 301 / old-page http://example.com/new-page
Remember: the URL that you want to be redirected must be indicated as a relative URL, that is, / laURL.
- Directory redirection. In the event that you have a directory that you want to redirect to another directory with another name, and in turn maintain the same structure of the directories and pages that depend on it:
For a top-level directory:
Redirect 301 / old-directory / http://www.example.com/directory-new/
For subdirectories:
Redirect 301 / directory / old-subdirectory / http://www.example.com/directory/subdirecty-new/
- Domain redirection. Imagine that you want to change your domain name, you have bought a new one, you want to change from .es to .com, etc.
Redirect 301 / http://www.example.com/
- IP redirection. It is important that the IP address of your website addresses the URL of your domain. For this you must do the following redirect in your htaccess.
IfModule mod_rewrite.c> RewriteCond% {HTTP_HOST} ^ 190 \ .90 \ .190 \ .90 RewriteRule (. *) Http://www.example.com/ $ 1 [R = 301, L, QSA] </IfModule>
Remember to indicate your IP and your website.
- 404 errors. errors. 404 errors can occur on any website and even if they are not critical errors, they must be controlled and redirected as far as possible.
As I have already told you, you can make 301 redirects in the htaccess through ftp or if you have WordPress, from Yoast. You can also make 301 redirects much easier with some plugins like 404 Redirected or Redirection.
One of the advantages of doing 301 redirects from htaccess is that you can do a lot of them at once. If you choose to do it from htaccess, you must apply this rule:
Redirect 301 / URL-error-404 / http://www.example.com/URL-destino
What is a 404 error and how to detect them?
Basically, a 404 error occurs when a page that is intended to be accessed can no longer offer the requested content. In this case, the page warns that the content is not found. However, the user can continue browsing the web.
404 errors do not directly affect SEO, however, they do worsen the user experience. If he accesses a certain page and encounters this type of error, it is quite likely that he will leave, increasing the bounce rate and decreasing the time spent on the web.
Precisely for these reasons it is recommended to customize the 404 error pages . For this you can put a nice message, offer alternative content or go to the Home of the site.
Whatever you choose, customize it so that at least the default page doesn’t come out.

Tools to detect 404 errors
Screaming Frog
It is an application that you can download to your computer, it offers you free analysis of up to 500 URLs , and by accessing ‘Response Codes’, applying the ‘Client error (4xx)’ filter, you will be able to see the errors of any website.

Google Search Console
The old Google Webmaster Tools can also warn you of 404 errors on your website. To do this, access and enter Tracking -> Tracking errors.
Ahrefs
This great tool, used above all to check incoming links, also allows us to control links with 404 errors.
Semrush and Sistrix
These two payment tools are very complete to do SEO positioning. They help you detect errors on your website, one of them is this one.
Broken Link Checker
This online tool allows you to study the broken links on your website. Both external and internal. The free version of this tool allows you to analyze up to 3,000 links.
