2

我正在使用 ColdFusion 9.1。

我正在从头开始重建一个站点并将现有域名指向它。该网站每天仍然有一些点击量,我想利用这一点。我想将这些页面请求重定向到主页,而不是当前正在服务的错误。

我只在寻找一个 ColdFusion 解决方案来将错误的请求移到主页。因此,如果他们请求 domain.com/BadPage.cfm?QString=XYZ,他们将被移动到 domain.com/。

我尝试在 Application.cfc 中使用以下方法,但我无法按照描述开始工作。它似乎没有任何效果。

<cffunction name="OnError" access="public" returntype="void" output="true">
<cfargument name="Exception" type="any" required="true" /">
<cfargument name="EventName" type="string" required="false" default="" />
<cfif Exception>
    <cflocation url="http://www.MyDomain.cfom/">
</cfif>
<!--- Return out. ---> 
<cfreturn />
</cffunction>

简而言之,最简单的 ColdFusion 重定向不良请求的方法是什么?

4

2 回答 2

5

onError 不会捕获丢失的模板。将 onMissingTemplate 处理程序添加到 Application.cfc:

<cffunction name="onMissingTemplate" returntype="Boolean" output="false">
    <cfargument name="templateName" required="true" type="String" />

    <!--- Put your home page file name here --->
    <cflocation url="/index.cfm" />

    <cfreturn true />
</cffunction>
于 2011-10-04T14:07:34.567 回答
4

使用 onMissingTemplate()

<cffunction name="onMissingTemplate">
   <cfargument type="string" name="targetPage" required=true/>

    <cflocation url="http://www.MyDomain.cfom/">
</cffunction>
于 2011-10-04T14:08:02.003 回答