When we talk about technical SEO, it is very common to talk about 301 redirects, but… are you clear about what we mean about 301 redirects or how to configure them on your website?
If you are still starting with your page or working on SEO, it is normal that the issue of 301 redirects still sounds like Chinese to you, but with this guide, we will solve this 🙂
In the theoretical part, I will explain what the 301 redirect is, what it is for and why these 301 redirects are so important for SEO.
In the practical part, we will see how to configure a 301 redirect from the .htaccess (also how to access and edit this file), and I will also give you some plugins to make 301 redirects in WordPress a piece of cake.
What is a 301 redirect?
A 301 redirect is a rule you establish on your website to make the traffic that arrives in a URL be permanently redirected to another URL.
In other words, with the 301 redirects, you are telling the browser that a certain page of your website (yourdomain.com/page1) has been permanently removed and where your visitors should now go (yourdomain.com/page2).
And, of course, if we create the 301 redirects correctly, the browser will listen to you and redirect your visitors automatically.
Types of redirects: 301 redirect and 302 redirect
Although in this article we will focus on 301 redirects, you must be clear about another type of redirect that exists: 302 redirects .
A 302 redirect works the same as a 301 redirect; the only difference is that in this case, you are telling Google that this redirect is temporary and not permanent.
Redirection 301 or redirection 302?
In the case of 301 redirections, the page moves permanently to a new place, while with 302 redirections, the page movement is temporary. This distinction tells search engines to keep a certain page (302) or replace it entirely with a new one (301).
The 301 redirect is permanent, so it is better for search engine optimization than a temporary redirect because it transfers incoming links from the redirected domain to the new one. Allowing the website to maintain its search ranking and prevent you from losing traffic.
The 302 redirects may be preferable to the permanent redirect in a few situations, such as when a website is undergoing maintenance.
Domain Authority 301 Rebranding : The mistakes you should avoid at all costs
Working with the 301 redirects requires paying close attention to some important points to avoid making mistakes that could affect traffic and domain authority. Therefore, we mention the five most common:
Set up a 302 redirect between your domain versions.
The 301 redirect points the power of an inbound link from one URL to another. For example, although it doesn’t look like it, xyz.com/blog and https://xyz.com/blog are two different URLs. Make sure to set up 301 redirections for all variations of your domain name. In this way, you optimize your presence in search engine results.
Set up a 301 redirect after creating a new page.
Make sure to set up 301 redirections before migrating your website content. Doing this will prevent you from losing traffic in the process.
Use the 302 redirects during the migration process.
Unless you’re temporarily migrating your website content while updating or maintaining it, use the 301 redirect to maintain inbound links and your search ranking while making changes to your domain.
Redirect links with outdated content and Domain Authority 301 Rebranding
If you don’t set up redirects for older links on your website (such as a link to your blog or home page), your users may have a bad experience accessing outdated links without redirection. Although the links will eventually take them to the new domain, this could take a few seconds when nothing is happening on the user’s screen.
Redirect to a page with a different intent than the destination page.
You can avoid redirecting your links to the wrong pages with little organization and keeping a clear record of what you’ve been doing.
You do not want to send your customers to the blog page when you want them to go to the purchase page. So doing the redirect correctly will help you have accurate SEO and give your visitors a better experience on your website.
In which cases do I need to create a 301 redirect? Examples.
I would tell you that there are hundreds of cases (well, I don’t know if that many 😛 ) where you may need to create a 301 redirect.
You already know that each page is a world, anyway I am going to show you the most common cases and those that we normally find among our clients:
When a product is removed from an ecommerce:
This is one of the most common. Each product has a URL, and when the product stops selling, it is normal to remove the page and redirect traffic to another very similar product or the category that the item was in.
You change the structure of the permalinks in WordPress:
We always recommend that you configure the permalinks in WordPress before publishing your website, but it is also possible that over time you need to create a new structure in your URLs.
In this case, the ideal is to create a 301 redirect to prevent your visitors from encountering a 404 error when they access the old URL.
When you remove a landing page from a specific offer:
If you created a landing page for a specific offer that you know you will not launch again, it is best to remove the landing page and refer your customers, for example, to your page Of start.
You change from HTTP to HTTPS:
Another possibility is that when you published your website, you did it without the HTTPS security protocol. It is not enough to activate the SSL certificate in WordPress or the CMS you use in this situation. But you also have to redirect all URLs with HTTP to HTTPS.
You change the domain:
Either for branding issues, SEO or because you are going to internationalize your brand. If you are going to change your website’s domain, but you want to keep the content and authority of the previous domain, the best solution is to create 301 redirects to direct all your visits to your new site.
Web with and without www:
You may have two versions of your website, one of the type yourdomain.com and the other www.yourdomain.com. That is, you have all the content duplicated. In this case, you will need to redirect all traffic from one URL to the other.
Why are 301 redirects so important for SEO?
There are three fundamental reasons for creating 301 redirects, and, if not done, they can seriously harm the SEO of your website:
- Because Google can detect duplicate content
- Because you want to pass the authority from the old URL to the new one
- Because you don’t want to offer a bad user experience
And now, I explain each of them in more detail.
301 redirect to avoid duplicate content
In cases where you have to change your domain, change from HTTP to HTTPS or from yourdomain.com to www.yourdomain.com. If you don’t do a 301 redirect, you will generate duplicate content.
You already know that Google likes this very, very little. It can penalize you for it and start losing positions in the ranking.
Redirect 301 not to lose authority
In addition to avoiding duplicate content, a 301 redirect is key if we want to transfer the power or authority of one URL to another. This happens many times when, for business strategy or any other reason, you change your website’s domain.
If your old domain had good authority, you send a lot of its strength to it so that the new domain ranks well and faster.
There are also other times when creating a 301 redirect can be a good option. Imagine you have a highly ranked blog post titled The Best of iPhone 6, and now you want to do one just like it for iPhone
12. Here you would have three possibilities:
- Modify the old post and introduce new content.
- Make a new post and wait for Google to rank you (if it does).
- Make a new post and create a 301 redirection in the old post to transfer the authority or link juicefrom the old post to the new one and position faster.
None of the three options guarantees success (you already know that Google’s algorithm does things its way), but it is an option you should always consider.
301 redirect so as not to affect the user experience
This is much better understood with an example:
Imagine that you have an online fashion store with a URL of the type tutienda.com/booties, but since the sale of booties hasn’t gone very well for you, you’ve decided to remove these products from your website. Well, in a case like this, what do you do?
- You keep the URL but without offering products in that category.
- You delete the page, and when a user reaches that URL, you return a 404 error.
- You automatically redirect your users to another page on your website, such as the URL tutienda.com/botas.
Option 1 and 2 would offer your users a negative shopping experience in your online store. While, with option 3 redirecting them to another of your pages, they can continue browsing your products and even end up making a purchase.
In this way, you are not affecting the user experience of your visits, and, therefore, you are not affecting your SEO either.
But are 301 redirects always good for SEO?
Not. For example, if a domain is penalized by Google or has very little strength, what good would pass its authority do us? Not at all; rather, quite the opposite.
When we say that 301 redirects are good for SEO, we refer only to specific cases. That are situations that, in the case of not doing them, Google could penalize us for duplicate content or, for example, poor user experience.
Therefore, as a general rule, 301 redirects can help you with SEO. Of course, without abuse 🙂
How to edit the .htaccess file?
Now that we have seen what a 301 redirect is, the types of redirects that exist and why they are so important for the SEO of your website, we move on to the practical part.
To create a 301 redirect, the most common is by modifying the .htaccess file of your website. That is a file that contains the directives that define the behaviour of our page.
Do you want to see how it’s done? Well, let’s go in parts.
First, I will explain how to modify the .htaccess file of your web page. And in the next section, we will see what rules to establish in the .htaccess depending on the type of 301 redirect you need to do.
- Edit the .htaccess file through the cPanel file manager
From the control panel of your hosting, you have access to the cPanel File Manager tool. Once you log in, in the “Settings” section, select the “Show hidden files (dotfiles)” option. Finally, click on “Save” to save the changes.
Once this is done, access the directory of your application, look for the .htaccess file, select it, and click on “Edit” with the right button.
Edit the .htaccess file by FTP
An alternative is to do it using a client like FileZilla. To do this, connect to your hosting via FTP and go to the directory of your website. Locate the .htaccess file and click on “View/Edit”.
You can also download the file to your computer and, once modified, upload it via FTP. To do this, rename the old .htaccess with a name like .htaccess_old and upload the new one. If everything works fine, you can delete the old file.
Edit the .htaccess file using plugins
Many SEO plugins like Rank Math or Yoast SEO also allow you to change your website’s .htaccess file to create 301 redirects.
- In Rank Math, you can do it from «General settings» → or «Edit .htaccess».
If you use Yoast SEO, go to “SEO” → “Tools” and select the “File Editor” option.
Before editing the .htaccess to set up a 301 redirect…
If you are going to edit your website’s .htaccess, make sure you have a backup copy of your site. Any change or erroneous condition can affect the operation of your website, even rendering it inoperative.
If you have your web hosting plan with us, such as SSD Hosting or WordPress SSD Hosting, remember that from your client area, you have access to Premium Backup, a tool that makes two backup copies of your website per day and that allows you to perform any restoration, even just the .htaccess file, in just a couple of clicks. So, you are always safe!
How to create a 301 redirect from .htaccess?
Now that we know how to edit the .htaccess file of our website, it’s time to configure the 301 redirects.
And do you know the worst? That there is no single rule that can be applied to all cases. As we have seen before, there are a lot of cases in which you will need to create a redirect, and, in each of them, the rules you have to set in the .htaccess are different.
In this guide, we will see the most common cases and the rules that you have to add to the .htaccess of your website to create the 301 redirect correctly. And I am almost sure that you will find a solution to yours 🙂
Do you use WordPress? Then you have it easier. There are some plugins that I will also show you that do these 301 redirects automatically and without touching the code.
Case 1: Redirect a page that we have removed to another URL
This case is very common in ecommerce when we stop selling a product and need to redirect that page to another with a similar item. The rule that we must add in our .htaccess is:
Redirect 301 /URL-antigua.html /URL-nueva.html
Case 2: 301 redirect from an old domain to a new one
If you made a domain change, you have to perform a 301 redirect all URLs from the old domain to the new domain. For this, the rule to establish would be:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www\.)?antiguo-dominio.com$ [NC]
RewriteRule ^(.*)$ https://nuevo-dominio.com/$1 [L,R=301]
Case 3: 301 redirect due to a change in WordPress permalinks
In this case, when changing the structure of your permalinks, you must make each published URL redirect to the new one. And you can do the redirect in bulk without having to go one by one.
Once you have chosen the new WordPress permalink structure, the easiest way to do this is to use a plugin like Simple 301 Redirects or Redirection, which creates the 301 redirections automatically, without the need for you to make any changes to it. htaccess to your website.
If you prefer to do it manually, you have to keep in mind that there are many different permalink structures; you can even set custom settings yourself. This means that the rules you have to establish in the .htaccess are different for each case.
I will show you four examples of WordPress permalink changes that are the most common. As I told you, since there are even custom structures, the options are endless!
Example 1: Changing the structure “Day and name” to “Ticket name”
If you make a change like the one I just showed you, the rule you must set in the .htaccess to make a 301 redirection of all your URLs is:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^[0-9][0-9][0-9][0-9]/[0-1][0-9]/[0-3][0-9]/(.*)$ $1 [R=301,NC,L]
Example 2 : Changing the structure “Month and name” to “Name of the entry”
In such a WordPress permalink change, we have to set this rule in the .htaccess:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^[0-9][0-9][0-9][0-9]/[0-1][0-9]/(.*)$ $1 [R=301,NC,L]
Example 3 : Changing the custom structure
(/%category%/%postname%/) to “Post Name”
If you have a custom structure of this type in your blog, you must add the following rule to your .htaccess:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^[^/]*/(.*)$ $1 [R=301,NC,L]
Example 4: Change from a “Simple” structure to any other link structure
If you have always configured the structure in WordPress and you are going to modify it, it is not necessary to make any changes in the .htaccess, choose the structure you choose.
In the simple link structure, the URLs are defined with the post ID, so when making any change in the permalinks, WordPress makes the redirection completely automatically.
Case 4: HTTP to HTTPS 301 Redirect
If you use WordPress, it is recommended that you do the 301 redirections with the Simple SSL plugin. This tool is responsible for automatically making all the changes and configurations on your website without the need for you to touch the .htaccess of your website.
And why better do it with a plugin? Because, as in the previous case, your WordPress could fall into a loop of infinite redirects, affecting the performance of your website.
If you prefer to do it manually, you must add the following rule to the .htaccess of your website and, in addition, modify the URL within the WordPress configuration. This rule is also valid for any other website that does not use this content manager:
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
You must have the SSL certificate installed and activated on your website for this to work.
Case 5: Redirect domain with “www” to domain “without www”, and vice versa
If you use WordPress, I recommend that you do not edit the .htaccess file of your website and that you directly make the changes from the administration panel of your site.
It is much easier, and, in addition, it may be the case that, if you edit it manually, your website falls into a loop of infinite redirects.
The way to do it would be from the “Settings” section of the WordPress administration panel. Add the domain as you want it to be displayed (with or without «www») and click on «Save changes» so that this modification is applied to your website.
If you don’t use WordPress, you can make this change by editing the .htaccess file as shown below.
Redirection 301 from «xyz.com» to «www.xyz.com»:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^xyz.com$ [NC]
RewriteRule ^(.*)$ https://www.xyz.com/$1 [L,R=301]
Redirection 301 from «www.xyz.com» to «xyz.com»:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www.xyz.com$ [NC]
RewriteRule ^(.*)$ https://xyz.com/$1 [L,R=301]
Conclusion
From removing an item from our online store to making our website work with an SSL certificate. When we make changes to our website, 301 redirects can be decisive for SEO.
Creating a 301 redirect from the .htaccess is not complicated if you know what rule to establish, but beware, as we have already seen, always make sure you have a backup of your website. No matter how small, any error can leave your website completely off.
And, as we have already seen, if you use WordPress, 301 redirects are a bit simplified. There are specific plugins that do it for you, and this will come in handy if you still don’t handle your website very well.
Now is your turn. Tell us, were you able to create the 301 redirect? Have you done them through .htaccees or used a WordPress plugin?
Have you done any 301 redirects on your website? How was the experience? Do you think these tips can help you if you have never done it? Leave us your comments!