4
votes

I've written a brief CFscript to encode/decode links:

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

This is in a file which is include in the site header (included on every page)

<cfinclude template="/includes/cfScriptFunctions.cfm">

This works fine in a 'normal' page:

<cfset link = link_encode(sub_menu.name)>

But, for SEO purposes I rewrite URLs via web.config:

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

When I land on this page, Coldfusion returns the error : "Variable LINK_DECODE is undefined". But, if I try to include the cfscript file in the page Coldfusion returns the error: "Routines cannot be declared more than once. The routine link_decode has been declared twice in different templates.". This tells me that the routine is available so why isn't it being found ?

update Ooops... My Fault ... I was calling the function before it had been included in the page ... Duh.

1
Are you sure it's not an issue of calling link_encode when you mean link_decode or vise versa? - Kyle Macey
Dead sure... I've edited my original post to include both encode/decode functions... Neither are found after the URL rewrite. - Pat Dobson
Can you paste the line that the error references exactly? - Kyle Macey
<cfset link = link_decode(URL.id)> - where URL.id has been encoded with the 'link_encode' routine. ( <cfset link = link_encode(sub_menu.name)> ) - Pat Dobson
@PatDobson your production site might be on a shared server, but surely your dev environment isn't?? - Adam Cameron

1 Answers

1
votes

Question... on your cfml page... when are you calling the link_decode? When are you including the header file? I've seen people call the link decode above their headers, to get queries built etc, to put data into the header, but the header has the cfscript. Check your flow, incase you're calling it before the include.