我写了一段简短的CFscript来编码/解码链接:
function link_encode(str) {
x = Replace(str, "&", "and", "ALL");
y = Replace(x, " ", "_", "ALL");
z = Replace(y, "/", "|", "ALL");
return z;
}
function link_decode(str) {
x = Replace(str, "and", "&", "ALL");
y = Replace(x, "_", " ", "ALL");
z = Replace(y, "|", "/", "ALL");
return z;
}
这是在一个文件中,它被包含在网站头部(每个页面都包含)
<cfinclude template="/includes/cfScriptFunctions.cfm">
这在“普通”页面中运行良好:
<cfset link = link_encode(sub_menu.name)>
但是,为了SEO的目的,我通过web.config重写URL:
<rule name="categories_1" stopProcessing="true">
<match url="category1/(.*)" />
<conditions logicalGrouping="MatchAll">
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
</conditions>
<action type="Rewrite" url="/category1.cfm?id={R:1}" />
</rule>
当我打开这个页面时,Coldfusion返回错误信息:"变量LINK_DECODE未定义"。但是,如果我尝试在页面中包含cfscript文件,Coldfusion会返回错误信息:"例程不能在不同的模板中声明多次。例程link_decode已经在不同的模板中声明了两次。"。这告诉我这个例程是可用的,那么为什么它没有被找到呢?
更新: 糟糕了,是我的错...我在函数被包含到页面之前就调用了它...傻瓜。
link_encode
时意图调用link_decode
或反之亦然吗? - Kyle Macey