How to Clean Up Duplicate HTTP 404 and 301 Redirects on WordPress Website
If you are using WordPress, you may have noticed that your website redirects are growing stale. More and more often, you are seeing HTTP 404 (page not found) or HTTP 301 (moved permanently) responses to website traffic. These types of redirects occur when a link (or any other item on a page, such as an image or video) triggers a redirection. However, there is usually no purpose behind these redirects other than to direct users to a specific page or section of the website. This wastes a lot of time and resources, as your engineers’ and webmasters’ time is best spent on improving your site’s content and functionality, not on debugging URL redirects. Because of this, it is in your best interest to clean up these redirects as soon as possible.
Luckily, WordPress makes this fairly easy. In this article, you will learn how to clean up HTTP 404 and 301 redirects on your site, using the built-in functionality of WordPress. This will not only save you time and resources, but it will also make your site much more stable and SEO-friendly.
Turn Off Redirects For Specific Posts
WordPress allows you to specify which posts should or should not have redirects. By default, all posts have redirects enabled. What this means is that every time someone clicks a link or enters a URL in the address bar, that post will be redirected to a different page. This makes sense for search engine optimization (SEO) purposes, as all of your posts are likely to have some link to them. However, for maintenance purposes, this is often not the case. For example, consider the case of a news blog that is focused on current events. In this case, you would not want to direct all of the traffic to that specific post to another place, as you might lose all of the interest from your current audience.
To prevent this, you can specify which posts should or should not have redirects, using the following code:
The above code will add a class (“no-redirect”) to the link to the specific post. Now, when someone clicks that link, they will be taken to the post, but the URL will not be redirected. This ensures that all the redirection is turned off for that one post only. From there, you can specify a new location for the redirection using the following code:
The above code will take users to the post, but the URL will not be redirected. Now, when someone clicks that link, they will be taken to the post, but the URL will not be redirected, as desired. From there, you can specify a new location for the redirection using the following code: