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], '-', ' ');

图片转代码服务由CSDN问答提供 功能建议

我最近更改了我的网站永久链接。 有些链接被谷歌索引,并且它们在搜索结果中。 但是 由于我的永久链接的更改,现在谷歌搜索将它们发送到错误404页面,这是非常糟糕的。</ p>

因此,我想将它们重定向到搜索页面提取关键字,而不是显示错误404 链接,例如:</ p>

我原来的链接现在不存在:</ strong> </ p>

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

现在如果是error404将其重写为搜索页面 </强> </ p>

 <代码> http://www.mydomain.com/search?q=some+title+of+my+site
 </代码> </预 > 
 
 

这是我的解决方案:它工作正常(没有错误页面: - ))</ strong> </ p>

使用htaccess将error404重定向到 搜索页面,然后通过爆炸URL设置搜索查询</ p>

  $ urlfrom404 = strtolower($ _ SERVER ['REQUEST_URI']); 
 $ tokens = explode('/',$ 乌尔 lfrom404); 
 $ removeHyphen = strtr($ tokens [sizeof($ tokens)-2],' - ',''); 
 </ code> </ pre> 
 </ div>

1条回答 默认 最新

相关推荐 更多相似问题