How to Redirect WordPress URLs

wp header

WordPress, a popular content management system, provides various tools and plugins to manage your website effectively. One essential feature is the ability to redirect URLs. Redirects help maintain SEO rankings, improve user experience, and manage site structure changes.

In this guide, we’ll cover different methods to redirect URLs in WordPress.

1. Using the .htaccess File

The .htaccess file is a powerful configuration file that controls how your web server behaves. To set up a redirect using this method, follow these steps:

Step 1: Access the .htaccess File

  1. Log in to your WordPress admin panel.
  2. Navigate to Appearance > Theme Editor.
  3. In the Theme Editor, locate and click on the .htaccess file on the right-hand side.

Step 2: Add Redirect Code

You can use the following code to perform various types of redirects:

  • Redirect a Single Page:
Redirect 301 /old-url/ http://www.example.com/new-url/
  • Redirect an Entire Site:
Redirect 301 / http://www.new-example.com/

Remember to replace http://www.example.com/new-url/ with your desired destination URL.

Step 3: Save Changes

After adding the code, click “Update File” to save the changes.

Screenshot of WordPress settings.

2. Using a WordPress Plugin

WordPress plugins provide an easy and user-friendly way to manage redirects. One of the most popular plugins for this purpose is “Redirection”. Here’s how to use it:

Step 1: Install and Activate the Plugin

  1. Log in to your WordPress admin panel.
  2. Navigate to Plugins > Add New.
  3. Search for “Redirection” and click on “Install Now”.

Step 2: Set Up the Redirect

  1. After installation, go to Tools > Redirection.
  2. In the “Add new redirection” section, enter the source URL (the URL you want to redirect from) and the target URL (where you want to redirect to).
  3. Choose the type of redirect (301 for permanent, 302 for temporary, etc.).
  4. Click on “Add Redirect” to save.

3. Using PHP Code

If you’re comfortable adding code directly to your theme’s files, you can use PHP to create redirects. Follow these steps:

Step 1: Access the Theme Editor

  1. Log in to your WordPress admin panel.
  2. Navigate to Appearance > Theme Editor.

Step 2: Edit the functions.php File

  1. In the Theme Editor, locate and click on functions.php on the right-hand side.
  2. Add the following PHP code to redirect a specific page:
function redirect_custom_page() {
    if( is_page('old-page-slug') ) {
        wp_redirect( 'http://www.example.com/new-page', 301 );
        exit();
    }
}
add_action( 'template_redirect', 'redirect_custom_page' );

Replace 'old-page-slug' with the slug of the page you want to redirect and 'http://www.example.com/new-page' with the destination URL.

Step 3: Save Changes

After adding the code, click on “Update File” to save.

Conclusion

Redirecting URLs in WordPress is a crucial aspect of maintaining a healthy website. Whether you prefer using the .htaccess file, a plugin, or coding with PHP, these methods offer flexibility based on your technical expertise. Choose the one that best suits your needs, and make sure to test the redirects to ensure they work as expected.

1 thoughts on “How to Redirect WordPress URLs

  1. zoritoler imol says:

    I was very happy to find this internet-site.I needed to thanks in your time for this excellent learn!! I undoubtedly having fun with each little little bit of it and I’ve you bookmarked to check out new stuff you blog post.

Leave a Reply

Your email address will not be published. Required fields are marked *