If you ever change the URL of a page or post on your WordPress site, you need to set up a 301 redirect to avoid losing traffic and SEO value. A 301 redirect is a permanent redirect that tells browsers and search engines that the old URL has moved to a new URL.

In this tutorial, you will learn:

  • What are the benefits of using 301 redirects
  • When you should use 301 redirects
  • How to set up 301 redirects in WordPress using different methods

What Are the Benefits of Using 301 Redirects

Creating 301 redirects has several advantages for your WordPress site, such as:

  • Improving user experience. Users will not encounter 404 errors or outdated content when they visit your site using old links. They will be automatically redirected to the new and relevant URL.
  • Preserving SEO value. Search engines will transfer the link equity and ranking power of the old URL to the new URL. This way, you will not lose your organic traffic and authority.
  • Updating URLs. If you restructure your site or change your domain name, you can update all the links to point to the correct URL. This will prevent broken links and confusion.
  • Avoiding duplicate content. If you have multiple URLs that display the same content, you can redirect them to one canonical URL. This will help search engines to index your site better and avoid penalties.

When You Should Use 301 Redirects

There are many situations where you may need to use 301 redirects on your WordPress site, such as:

  • Deleting or replacing content. If you have a page or post that is no longer relevant or accurate, you can delete it and redirect the traffic to a new page or post that covers the same topic.
  • Moving to HTTPS. If you switch from HTTP to HTTPS by installing an SSL certificate, you need to redirect all the HTTP URLs to HTTPS URLs. This will ensure that your site is secure and consistent.
  • Moving to a new domain. If you change your domain name for any reason, you need to redirect all the old domain URLs to the new domain URLs. This will help you retain your existing visitors and SEO value.
  • Improving content. If you have a page or post that is underperforming or outdated, you can improve it by creating a new version with better content and design. You can then redirect the old URL to the new URL.

How to Set Up 301 Redirects in WordPress Using Different Methods

There are several ways to create 301 redirects in WordPress, depending on your preference and technical skills. Here are some of the most common methods:

Method 1: Using cPanel

One of the easiest ways to set up 301 redirects in WordPress is to use cPanel, which is Hostinger’s custom control panel. You can use cPanel’s Redirects tool to create and manage redirects without touching any code.

To use cPanel’s Redirects tool, follow these steps:

  • Log in to your cPanel account.
  • Under Domains, click on Redirects.
  • In the Add New Redirect section, enter the old URL in the Source field.
  • Enter the new URL in the Destination field.
  • Select Permanent (301) from the Type drop-down menu.
  • Click Create.

That’s it! Now, anyone who visits the old URL will be redirected to the new URL.

Method 2: Using AIOSEO Plugin

Another way to set up 301 redirects in WordPress is to use a plugin. There are many plugins that can help you with this task, but we will use AIOSEO as an example. AIOSEO is a plugin that allows you to optimize your WordPress site for SEO, including creating and managing redirects.

To use AIOSEO, follow these steps:

  • Install and activate the plugin from the WordPress dashboard.
  • Go to All in One SEO > Redirections from your WordPress dashboard.
  • In the Add New Redirection section, enter the old URL in the Source field.
  • Enter the new URL in the Target field.
  • Select Permanent (301) from the Type drop-down menu.
  • Click Add Redirect.

That’s it! Now, anyone who visits the old URL will be redirected to the new URL.

Method 3: Using .htaccess File

Another way to set up 301 redirects in WordPress is to use .htaccess file, which is a configuration file that controls how your web server handles requests. You can edit .htaccess file to add redirect rules manually.

To use .htaccess file, follow these steps:

  • Access your WordPress files using FTP or cPanel File Manager.
  • Locate and open .htaccess file in your root directory (usually public_html).
  • Add the following code snippet at the end of the file:
Redirect 301 /old-url /new-url
  • Replace /old-url and /new-url with your actual URLs.
  • Save and close the file.

That’s it! Now, anyone who visits the old URL will be redirected to the new URL.

Method 4: Using PHP Script

Another way to set up 301 redirects in WordPress is to use a PHP script, which is a programming language that runs on your web server. You can create a PHP script to add redirect rules dynamically.

To use a PHP script, follow these steps:

  • Access your WordPress files using FTP or cPanel File Manager.
  • Locate and open the functions.php file of your active theme. You can find it in wp-content/themes/your-theme-name/functions.php.
  • Add the following code snippet at the end of the file:
function my_custom_redirects() {
  // Check if the current URL matches the old URL
  if ( $_SERVER['REQUEST_URI'] == '/old-url' ) {
    // Redirect to the new URL with a 301 status code
    wp_redirect( '/new-url', 301 );
    // Exit the script
    exit;
  }
}
// Hook the function to the template_redirect action
add_action( 'template_redirect', 'my_custom_redirects' );
  • Replace /old-url and /new-url with your actual URLs.
  • Save and close the file.

That’s it! Now, anyone who visits the old URL will be redirected to the new URL.

Conclusion

In this tutorial, you have learned how to set up 301 redirects in WordPress and when you need them. You have also learned different methods to create and manage redirects, such as using hPanel, plugins, .htaccess file, or PHP script.

We hope you found this tutorial helpful and easy to follow. If you have any questions or feedback, please leave a comment below. Thank you for reading!

Categorized in: