WordPress 301 Redirects With Code Snippets

Today I’m going to talk about WordPress 301 redirects. I will go over the best-practiced method while using the 301 redirect directive. In addition, I will write some code snippets which you can use for yourself.

What Is 301 Redirect?

A 301 redirect directive is one of a few HTTP response status code directives you can use. Moreover, it’s one of the most powerful and commonly used today.

In short, a 301 directive simply tells the client (user/ search engine bot, etc) that the URL they are trying to reach moved permanently to a new address. Resulting in an instant redirect to the new address. This is an essential tool in your arsenal.

Why Should I Use 301 Redirect?

Let’s take a look at this from an SEO point of view, followed by a user’s point of view.

You are running a blog with a lot of pages and posts. Naturally, sometimes things change and you might delete a post or a page. However, what most people without SEO knowledge don’t know, is, by doing soo you essentially just wipe away your SEO juice provided by the deleted content.

Meaning, your posts rank on search engines. Let’s say you write a post about, for instance: “Best WordPress Plugin”. The post gets indexed by search engine bots and ultimately indexed.

Now, if you just wipe away content without providing some sort of a response, this will result in a 404 response and a loss in the “SEO Juice” of that content. Moreover, you should know that a 404 response code is not a good thing for search engines. Especially if “something” was there before, and now it’s not.

Finally, if all of the above doesn’t affect you, think about the potential users generated from search engine traffic (Organic Traffic) you just lose due to a 404 page instead of real content.

How To Add 301 Redirect?

In this tutorial, I will be showing you the best method to perform a 301 redirect. However, keep in mind that there are a few ways to achieve this, so you might see different methods applied on different websites.

Our method is the way of editing the htaccesss file and providing the directives directly to our web server. This example will feature an Apache webserver. This is the best way for a few reasons, one of the main ones is simply due to the fact that it goes directly to our web server, so SPEED is a major factor here.

WordPress 301 Redirect htaccess Method

Before we begin, the htaccess file is a critical component. Make sure you backup the file before you edit it in any way.

Redirect Directive:

#Options +FollowSymLinks
RewriteEngine on
RewriteRule ^example-post/?$  https://website.com/example-post-new-location-url/ [R=301,L,NC]

We provide the firest segment by writing the URL without the whole website prefix of “https://…”. Instead, we use what’s after the “/”. So if I had a post located at:

https://website.com/example-post – > example-post

In the second segment we provide the full website URL, much like so:

https:// website.com/example-post-new-locationn-url

Moreover, you also use 301 directives when you change a domain name. If you want to redirect specific posts from the old domain to the new one, this will look like:

#Options +FollowSymLinks
RewriteEngine on
RewriteRule ^example-post/?$ https://website.com/example-post-new-location-url/ [R=301,L,NC]

Now, If you want to redirect the whole old domain and whatever is under it, then use:

RewriteRule ^(.*)$  https://newdomain.com/$1 [R=301,L]

Keep in mind, in order for the redirects to work you still must own the old domain. Moreover, you edit the htaccess of the old domain.

Final Words About WordPress 301 Redirects

Well, I hope you found this article useful. Always remember, don’t just delete posts and pages in your blog. Keep in might that they might have been indexed and by doing so, ultimately you will hurt your site’s SEO ranking.

But you don’t have to use code snippets by editing .htaccess. You can also use the plugin such as 301 Redirects.

Finally, with great power, comes great responsibility. Use this wisely.

This domain (and site) is for sale. Price is 240 EUR. If you are interested contact me via form to discuss further. Domain registered till 2030 (September), DR 45, links from sites like Cloudways, ElegantThemes, Freemius, WPTavern, etc. Payment and transfer either via bank transfer or via Escrow (buyer pays fees). Or you can buy from Dan.com (price higher because of their fees) https://dan.com/buy-domain/ingothq.comCONTACT ME
+