How Can I Redirect A Page In WordPress Without A Plugin? I Need to Redirect Page کربنات کلسیم To /Calcium-Carbonate/ . I Don’t Know What To Do Please Help Me.
Asked
Active
Viewed 25 times
0
-
Does this answer your question? [How to properly make 301 redirect](https://stackoverflow.com/questions/48886601/how-to-properly-make-301-redirect) – Howard E Apr 19 '20 at 10:59
2 Answers
0
Best way is to use .htaccess file and 301 redirection. Or you can use 'wp_redirect()' if needed. But .htaccess is better solution.
Redirect 301 /old-url /new-url

Boris
- 154
- 2
- 7
0
used the following code .
please paste the given function in themes function.php
following snippet add in function.php
function redirect_dest() {
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);
switch ($currenturl_relative) {
case '[from slug]':
$urlto = home_url('[to slug]');
break;
default:
return;
}
if ($currenturl != $urlto)
exit( wp_redirect( $urlto ) );
}
add_action( 'template_redirect', 'redirect_dest' );
and in switch case code please replace the following slug path :
from slug: enter source path slug
to slug: destination path slug
switch ($currenturl_relative) {
case '[from slug]':
$urlto = home_url('[to slug]');
break;
default:
return;
}
Similarly if your URL is;
https://www.example.com/05/18/some-page
The slug will be:
/05/18/some-page

Ganesh Aware
- 21
- 2