views:

126

answers:

1

Hi friends, I need a CFM script to place on my website homepage.

If a visitor arrives from a search engine using a a certain search phrase, I want to redirect them to various pages.

For example:

The following searches would redirect to the following pages:

become a business coach -> http://www.businesscoach.com/BusinessCoaching.html

find a business coach -> http://www.businesscoach.com/go/bc/find-a-business-coach/index.cfm

please help me to do this...

Thanks

+3  A: 

First you need to analyze the referer string, if not empty. This can be done in different ways.

Consider this Google-like string:

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

Same referer.cfm should perform the check.

Say, simplest and totally not flexible way is to search through the referer:

<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>

More advanced approach can be the search through the search query keywords. First you should split the string:

<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>

How to search the keyword -- up to you, maybe query the database and search matches, maybe create configuration directly in code. In both ways I'd used set of structures like this example:

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

When keywords match the search phrase, use url to relocate.

Sergii
This should go in Application.cfc/.cfm. Also, if an HTML page is your landing, Application.cfc won't even fire. (Unless you've configured your web browser to tread html pages as cfm.)
Al Everett