2009-12-16 103 views

回答

3

首先您需要分析引用字符串,如果不是空的。这可以通过不同的方式完成。

考虑这个类似谷歌的字符串:

<p><a href="referer.cfm?q=become+a+business+coach&ie=utf-8&oe=utf-8">test</a></p> 

referer.cfm应该进行检查。

说,最简单的,完全不灵活的方式是通过引荐搜索:

<cfif cgi.HTTP_REFERER NEQ "" 
     AND FindNoCase("business", cgi.HTTP_REFERER) 
     AND FindNoCase("coach", cgi.HTTP_REFERER)> 

    <cflocation url="http://where.you.want.to.go.tld/" addtoken="false"> 

</cfif> 

更先进的方法可以通过搜索查询的关键字搜索。首先,你应该拆分字符串:

<cfif cgi.HTTP_REFERER NEQ ""> 

    <!--- extract the search phrase ---> 
    <cfloop list="#cgi.HTTP_REFERER#" delimiters="&" index="token"> 

     <cfif FindNoCase("?q=", token)> 

      <cfset phrase = ListLast(token, "?q=") /> 

      <!--- extract the keywords ---> 
      <cfloop list="#phrase#" delimiters="+" index="keyword"> 

       <!--- search needed keyword and perform relocation ---> 

      </cfloop> 

     </cfif> 

    </cfloop> 

</cfif> 

如何搜索的关键词 - 你的,也许查询数据库和搜索匹配,也许在代码中直接创建配置。在这两个方面,我倒是用一套这样的例子结构:

<cfset rule = StructNew() /> 
<cfset rule["keywords"] = "become,business,coach" /> 
<cfset rule["url"] = "http://where.you.want.to.go.tld/" /> 

当匹配搜索短语关键字,请使用网址搬迁。

+0

这应该在Application.cfc/.cfm中进行。另外,如果您的登陆页面是HTML页面,Application.cfc甚至不会触发。 (除非你已经配置你的网页浏览器来将HTML页面作为cfm进行处理。) – ale 2010-06-02 18:03:48