精彩专题推荐:建站之入门课 建站之必修课 建站之关键课 网站价值所在 流量提高专题 css+div 标准 个人网站打造全过程
  • 让你的网站产生收益赚钱,有博客和网站的绝对不能错过
  • 将指定的流量带到你的网站,为你站增加有效的访客,为你提升业绩
  • PHP匹配变音使404页面更加智能化

    来源:网络整理 时间:07-11-05 点击: 点击这里收藏本文

    清单 8. sortResults 和 containsTest 子例程
                   

    以下为引用的内容:
    sub sortResults
    {
      # simply procedue to sort an array of 'score ## filename' entries
      my @scored = @_;
      my @idx = (); #temporary index for sorting
      for my $entry( @scored ){
        # create an index of scores
        my $item =  substr($entry,0,index($entry,'##'));
        push @idx, $item;
      }
     
      # sort the index of scores
      my @sorted = @scored[ sort { $idx[$b] <=> $idx[$a] } 0 .. $#idx ];
     
      return( @sorted );
     
    }#sortResults

    sub containsTest
    {
      my @matchRes = ();
      my $inLink = $_[0];
      for my $fileName ( keys %mt )
      {
        my $inLinkMeta = Metaphone($inLink);
        my $metaList =  $mt{$fileName}{metaphones};
        next if( $metaList !~ /$inLinkMeta/i );
        push @matchRes, "$mt{$fileName}{score} ## $fileName";
      }#for filename keys in metaphone hash
      return(@matchRes);
    }#containsTest

    修改 Apache httpd.conf 文件

    上面所设计的 MetaphoneSuggest 脚本是一个将从 Apache 中直接调用的 cgi-bin 脚本。要运行 MetaphoneSuggestscript 脚本,我们需要对 httpd.conf 文件进行适当修改,否则将显示 404 错误页面。比如说,如果默认的 httpd.conf 文件含有以下部分:

    清单 9. 默认 httpd.conf 部分
                   

    以下为引用的内容:
    # Customizable error responses come in three flavors:
    # 1) plain text 2) local redirects 3) external redirects
    #
    # Some examples:
    #ErrorDocument 500 "The server made a boo boo."
    #ErrorDocument 404 /missing.html
    #ErrorDocument 404 "/cgi-bin/missing_handler.pl"
    #ErrorDocument 402 http://www.example.com/subscription_info.html

    在注释掉的 ErrorDocument 代码行之后插入如下代码:ErrorDocument 404 "/cgi-bin/MetaphoneSuggest"。确保 MetaphoneSuggest 和 metaphonesScore.txt 文件位于 Web 服务器的 <document_root</cgi-bin/ 目录下。以根用户身份发起服务器重启命令:例如 /usr/local/apache2/bin/apachectl restart,至此灵活的建议机制将彻底结束笨拙的 404 错误。

    结束语
     
    记住,使用 MetaphoneSuggest 程序中所描述的工具时,错误条件必须为 404 页面。试着提供少量建议的选择并保持设计的简单性。请教 Web 设计方面的知名人士,了解他们为什么没有提供自动链接建议,或者开展各种可用性研究,了解何种情况下最适合在站点中实现链接建议工具。

    本文提供了各种工具和代码,用于在 404 页面中创建实用的链接建议。但是,这些示例都已经实现,您可以通过它们提供一些复杂的功能,而不仅仅是简单的目录链接或拼写建议。通过对特定站点和内容进行调整,笨拙的 404 错误将不复存在。

    9 7 3 1 2 3 4 4 8 :

    用户评论

    广而告之