How to redirect a page in WordPress with plugin, without plugin with server

How to redirect a page in WordPress with plugin, without plugin with server: Here’s a simple guide on how to redirect a page in WordPress. What is a redirect?

A redirect is a way to send visitors from one URL to another. It’s useful for changing page locations, moving websites, or fixing broken links.

Ways to Redirect Pages:

  1. Using a Plugin
  2. Using Code
  3. Using a Hosting Panel (like cPanel/hpanel)

Redirecting Pages on the Same Site

If you’re redirecting pages within the same website, using a plugin or adding code is usually sufficient. For redirecting from one domain to another (site-to-site), you’ll need to use your hosting panel, such as cPanel or Hostinger, since domain-level redirects are different from page redirects.

how to redirect a page in wordpress with plugin

There are several free plugins available for redirection, but here are two recommended options:

  • Redirection Plugin: Install and set up the plugin. You simply add the old URL and the destination URL to create a redirect.
  • Rank Math SEO Plugin: This free SEO plugin has a redirection option in its dashboard. After enabling the redirection feature, you can easily add new URLs in the provided fields.
  • Go to dashboard
  • if u enabled redirections in rankmath you will find redirections in left nav, see below image
how-to-redirect a page in wordpress-with rank math plugin
how-to-redirect a page in wordpress-with rank math plugin

Some SEO plugins also offer premium versions with advanced redirection options.

Read my latest posts here:

How to redirect one page to another page with code

If you prefer to add a redirect manually using code, follow these steps:

  1. Tip: Before making changes to your code, create a child theme to ensure your updates aren’t overwritten during theme updates.
  2. Inside your child theme’s folder, locate the functions.php file and add the following code: Code Example 1:
// Example of redirecting a page
function quadlayers_redirect() {

    if (isset($_SERVER['HTTPS']) && 
        ($_SERVER['HTTPS'] == 'on' || $_SERVER['HTTPS'] == 1) || 
        isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && 
        $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https') {
        $protocol = 'https://';
    } else {
        $protocol = 'http://';
    }

    $currenturl = $protocol . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
    $currenturl_relative = wp_make_link_relative($currenturl);

    error_log("Current URL: " . $currenturl_relative); // Log current URL

    switch ($currenturl_relative) {
        case '/old-url/':
            $urlto = home_url('/new-url/');
            break;
        default:
            return;
    }

    error_log("Redirecting to: " . $urlto); // Log redirection URL

    if ($currenturl != $urlto)
        exit(wp_redirect($urlto));
}

add_action('template_redirect', 'quadlayers_redirect');

You can use these redirections for not-found pages regularly.

Example:-2


// Multiple URL redirections

function redirect_page() {
    // Check for HTTPS and set the protocol
    if (isset($_SERVER['HTTPS']) && ($_SERVER['HTTPS'] == 'on' || $_SERVER['HTTPS'] == 1) ||
        isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https') {
        $protocol = 'https://';
    } else {
        $protocol = 'http://';
    }

    // Get the current URL
    $currenturl = $protocol . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
    $currenturl_relative = wp_make_link_relative($currenturl);

    // Define the redirection map
    $redirection_map = array(
        '/about/' => '/contact-us/'
		
    );

    // Check if the current URL needs to be redirected
    if (array_key_exists($currenturl_relative, $redirection_map)) {
        $urlto = home_url($redirection_map[$currenturl_relative]);

        // Perform the redirection if the current URL does not match the target URL
        if ($currenturl != $urlto) {
            wp_redirect($urlto, 301);
            exit; // Make sure to exit after the redirection
        }
    }
}

add_action('init', 'redirect_page');

Video Example

Explanation of video: if you see here, i am entering https://thefallen.in/about/ and its redirecting to https://thefallen.in/contact-us/

You can also try multiple urls inside the array,

Redirecting from One Domain to Another

To redirect an entire domain or a page from one domain to another, you’ll need access to your hosting panel (e.g., cPanel or Hostinger). Domain-level redirections are set up differently from page-level redirects.

I will explain how to do in hostinger panel.

Step: 1 – Go to hostinger dashboard

Step 2: Go to the domain section.

Step 3: Find redirect features.

how to redirect  one domain page to another domain page

how to redirect  one domain page to another domain page

For example, in Hostinger’s cPanel, there’s an option for “Redirects,” where you can add the source domain and target domain for a site-wide redirect.

This is how you can manage page and domain redirection in WordPress!

Hire me here: My Profile

Give me a tip if you like. Gumroad profile Purchase any product add a tip there.

Share your love
The Fallen
The Fallen
Articles: 49

Leave a Reply

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

hii
index
0%

How did you reach us?