drj14664 2013-02-20 02:03
浏览 23
已采纳

htaccess - 如果链接不存在,则重定向到搜索

I have recently changed my site permalink. Some links are indexed by google and they are in search result. but due to changing of my permalink, now google search send them to error 404 page and that is really bad.

So, instead of showing error404 i want to redirect them to search page extracting keyword from link, for example:

my original link which does not exist now:

http://www.mydomain.com/2013/01/some-title-of-my-site/

Now if it is error404 rewrite them to search page

http://www.mydomain.com/search?q=some+title+of+my+site

Here is my solution: it is working and awesome (no error page :-))

using htaccess to redirect error404 to search page and then set search query by explode url

$urlfrom404 =   strtolower($_SERVER['REQUEST_URI']);
$tokens = explode('/', $urlfrom404);
$removeHyphen = strtr($tokens[sizeof($tokens)-2], '-', ' ');
  • 写回答

1条回答 默认 最新

      报告相同问题?

      相关推荐 更多相似问题

      悬赏问题

      • ¥15 如何修改为正确的?求解决
      • ¥15 django访问管理员界面问题
      • ¥20 python homework完成
      • ¥20 求解 多变量系统的最小二乘辨识问题的推导以及matlab仿真
      • ¥15 arduino esp8266 Blinker编译报问题
      • ¥15 ubuntu18.04运行模型,直接死机
      • ¥30 (问卷调查)莫名其妙丢了u盘,你们会是什么心理状态
      • ¥100 Spark+android应⽤案例
      • ¥15 yolov8 目标检测 重叠 遮挡
      • ¥20 微信聊天记录如何部署到服务器上