[英]Redirecting pre-existing URL to a wordpress permalink url
I previously had a static website with a page such as www.example.com/pages?id=123 我以前有一个静态网站,其页面为www.example.com/pages?id=123
I remade that website into a wordpress site with permalinks such as: www.example.com/Iam-a-url 我将该网站改制成了具有永久链接的wordpress网站,例如:www.example.com/Iam-a-url
Now here is my problem, my existing users are visiting www.example.com/pages?id=123 and get a page not found error(because of course it doesnt exist). 现在这是我的问题,我现有的用户正在访问www.example.com/pages?id=123并显示找不到页面错误(因为它当然不存在)。 How do I go about redirecting them to www.example.com/Iam-a-url 如何将他们重定向到www.example.com/Iam-a-url
Place this into your functions.php 将此放入您的functions.php
function _redir_old_site(){
if( (stripos($_SERVER['REQUEST_URI'], 'pages?id=') !== FALSE) ){
//you can set the redirect based on the id
$oldID = $_GET['id'];
//set default page id
$nowID = 5;
switch( $oldID ){
case '123':
//the page id now
$nowID = 46;
break;
//....and so on.....
}
header("location:". get_permalink($nowID) );
exit;
}
}
add_action('template_redirect', '_redir_old_site', 1);
good luck! 祝好运! :) :)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.