Redirect When Search Query is an Exact Title in Wordpress

十年热恋 提交于 2019-12-12 01:48:27

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!