How to do 301 redirects in WordPress

Tutorials 0 lượt xem

301 redirects are one of the basic knowledge that every website owner needs to stand firmly. 

If you don’t know 301 redirects, you can lose SEO value for the webpage (a page of your website) and your website as a whole.

Today we’re going to discuss the basics around 301 redirects. Then we’ll show you how to implement 301 redirects.

301 redirect for basic knowledge

​Search Ranking

As you already know:

Google is currently the largest search engine. It works by ranking web pages according to specific queries.

Based on various criteria, Google ranks one webpage higher than another.​

When your website has a high ranking, it will attract a large amount of traffic. Large traffic will have large sales. Simple is that.

Thus SEO (search engine optimaztion) was born. It is a set of techniques that help websites rank higher in Google search results.

What is Permalink?

Permalink is the website address or URL. It is the permanent address of a website.

Permalink will appear in Google search results. It’s how Google sends traffic to that address. For example, the permalink of an article on the website has the following form: yourdomain.com/post-slug

What is a 301 redirect?

Google talked about this, let’s explain in more detail: 

If you need to change the URL of a page that appears in search engines, we recommend using a 301 redirect on the server. This is the best way to ensure that users and search engines arrive at the correct page. A 301 status code means a page has been permanently moved to a new location. 

301 redirects are permanent redirects. Simply put, you have a page example.com/page-a now you want to move to the new address example.com/page-b

If you don’t do a 301 redirect when page a is accessed it will give you a 404 error. 

If you do a 301 redirect and Google Bot will be redirected to Page B. 

 Why do you need a 301 redirect?

Like I said if you don’t do a 301 redirect, a 404 error will appear. Neither users nor Google like going to dead pages.

When Google detects a page no longer exists it will drop the rankings. In other words it will not send traffic to that page. Instead it sends traffic to another site. Is this reasonable?

Performing a 301 redirect will help you push the full ranking power of the old page to the new page. According to Moz , 301 redirects will push 90-99% of link juice (ranking power) to the new page. ​

So your new page still achieves the same ranking as the old one.​

There are a few situations where you need a 301 redirect

There are a few situations where you need to do a 301 redirect:

1. Change Permalink Structure in WordPress

Usually this should be done after installing WordPress. Never do this when the website already has content.

But some of you who are new to WordPress do not do this step when installing the website. After creating quite a bit of content, I discovered my permalink was not SEO friendly. 

In this situation if you change your Permalink structure you need to do a 301 redirect. 

2. Change the Permalink or URL of a post/page

This is also a fairly common situation when administering a WordPress website. If you change the URL of the post/page, remember to 301 redirect.

3. Merge multiple posts into one

This is the same case as above. Only difference here you have multiple posts. But you find it unreasonable.

You want to merge them into a new post. Then delete the old posts.

Here you need to redirect all old articles to new aggregated articles.

4. Install SSL certificate for website.

When you move your website from http to https, you need to do a 301 redirect. How to do that you see in the article how to install your SSL certificate.

5. Change domain name

If you need to change the domain name for your website, a 301 redirect is a step not to be missed. See how to transfer domains without worrying about losing your rank.

How to 301 Redirect in WordPress Using Plugins

If you do 301 redirects for articles in your website, you should use the Simple 301 Redirects plugin . 

In case you are doing a larger 301 redirect such as installing an SSL certificate or changing a domain name, you should manually change the .htaccess file (as instructed below). 

First you need to install and activate the plugin. Then you go to Settings -> 301 Redirects to do the redirect. 

Redirect from one page to another

Let’s say you want to redirect from yourdomain.com/old-page to yourdomain.com/new-page. 

You do the following:

Request : /old-page

Destination : /new-page. 

301 redirect in wordpress 1

Click the Save Changes button to save the configuration again. Now you test again by accessing the old URL. You will be redirected to the new URL automatically. It’s done. 

Use wildcards for more complex 301 redirects

Wildcard allows you to redirect multiple pages to one or the other.

Let’s say you have a directory of posts using the following URL structure:  yourdomain.com/my-pham/post-slug

Now you just switched to using a new URL structure like this: yourdomain.com/lam-dep/post-slug

In such a situation you can do a 301 redirect as above. But doing each post is clearly not productive. 

This is when you need to use the wildcard feature like this: 

Request : /my-pham/*

Destination : /lam-dep/*

Tick ​​Use Wildcards. 

301 redirect in wordpress 2

301 redirect by changing the .htaccess file

Here are a few examples of 301 redirects by manually changing the .htacess file:

To redirect one page to another, you should use the plugin as above. But if you want to change the .htaccess file, here is the code: ​

Redirect 301 /old-url /new-url​​

​301 redirect when switching to SSL

Usually you use Really Simple SSL plugin . But if you need to change it manually, here is the code: 

RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

301 redirect when changing domain name 

Remember to refer to the article on changing the domain name without worrying about losing your rank to see the redirect code. 

It’s all about 301 redirects. 

Generally, whenever you change the URL of any content in your website, do a 301 redirect. 

If you have any other issues around 301 redirects, leave a comment below. 

Bài viết liên quan