问题
I have two post titles in Wordpress:
post_title: gröband
permalink: www.example.com/groband.html
post_title: groband
permalink: www.example.com/groband-2.html
I want redirect when search query is "gröband
" to www.example.com/groband.html
if search query is "groband
" redirect to www.example.com/groband-2.html
回答1:
Edit your search template in theme editor and add this top
<?php
if(isset($_GET['s'])){
$url ="";
switch($_GET['s']){
case 'gröband':
$url = "http://www.example.com/groband.html";
break;
case 'groband':
$url = "www.example.com/groband-2.html";
break;
}
if(!empty($url)){
header("Location: ".$url);
}
}
?>
or
<?php
if(isset($_GET['s'])){
switch($_GET['s']){
case 'gröband':
header("Location:http://www.example.com/groband.html");
break;
case 'groband':
header("Location:http://www.example.com/groband-2.html");
break;
}
}
?>
来源:https://stackoverflow.com/questions/27633391/redirect-when-search-query-is-an-exact-title-in-wordpress