Hi,
Open your “functions.php” file located in your theme (preferably a child theme) & paste the following code into it with required page slug.
function redirect_page() {
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 = 'https://';
}
$currenturl = $protocol . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
$currenturl_relative = wp_make_link_relative($currenturl);
switch ($currenturl_relative) {
<strong> case '[from slug]':</strong>
$urlto = home_url('<strong>[to slug]</strong>');
break;
default:
return;
}
if ($currenturl != $urlto)
exit( wp_redirect( $urlto ) );
}
add_action( 'template_redirect', 'redirect_page' );
Step 1: Replace the sections in bold including the square brackets with the slugs you got from
Step 2: Save your changes.
All done!
Thanks.
-
This reply was modified 4 years, 6 months ago by
bcworkz. Reason: code fixed