Home > SEO, Tutorials > Search Engine Friendly URL’s – coldfusion, cold fusion, CFML)

Search Engine Friendly URL’s – coldfusion, cold fusion, CFML)

June 21st, 2007

I have a client that has a site in coldfusion and I needed to fix their URL’s so they are search engine friendly. I don’t have access to the server so I needed a coldfusion solution. What I wanted was to make it so there were no ?, &, or = signs in the URL and convert them to /’s. I also wanted to 301 redirect the old URL’s to the new URL’s. Here is what I came up with

<cfset urlstring = cgi.path_info>
<cfloop from="1" to=#ListLen(urlstring,"/")# index="i">
<cfif i mod 2>
<cfset paramName = "URL." & ListGetAt(urlstring,i,"/")>
<cfelse>
<cfparam name="#paramName#" default="#ListGetAt(urlstring,i,"/")#">
</cfif>
</cfloop>

<cfif cgi.QUERY_STRING contains "=">
<cfset moveUrl = #rereplace (cgi.QUERY_STRING,"[=?&]","/","ALL")#>
<cfset newUrl = #cgi.path_info# & "/" & #moveUrl#>
<cfheader statuscode="301" statustext="Moved permanently">
<cfheader name="Location" value="#newUrl#">
</cfif>

Categories: SEO, Tutorials Tags: