06.21.07
Search Engine Friendly URL’s - coldfusion, cold fusion, CFML)
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>
Technorati Tags: coldfusion, cold fusion, CFML, seo, url, Search Engine Friendly URL’s, google, search engine


DazzlinDonna said,
06.22.07 at 2:21 pm
I almost got goosebumps seeing ColdFusion code in a SEO blog post. How fun! Just a little jolt of adrenaline to an old CF’er turned SEO.
bayouboy7303 said,
06.27.07 at 3:43 pm
Is it still necessary to remove the “?” and other symbols from CF code so search engines can read them?
Thanks!
ogletree said,
06.27.07 at 8:43 pm
No it is not necessary. Google does a good job of treating those as pages. There are other reasons to avoid the question mark. I will make a post about it.
Jason Bartholme’s SEO Blog » Blog Archive » 101 ColdFusion Resources To Add To Your Toolbelt of Awesomeness said,
07.09.07 at 1:35 pm
[…] Search Engine Friendly URL’s - ogletreeseo.com […]
Joe said,
08.22.07 at 8:12 am
Nicely done!
I had looked into the path_info variable while writing an application but I wasn’t sure exactly what it did. I didn’t even think about the permanent redirect as well, but it makes sense to do.
Alex Bell said,
10.23.07 at 12:53 am
[…] Hello
Great resource! I’ve been meaning to do a similar post. It’s interesting.
Alex Bell […]
James said,
10.25.07 at 7:52 am
Hi Great Script, It works wonderfully…
I do have a possible glitch however. When I try to submit a form from a page loaded through the sEFurls script, my cf code is stating that the #form.variable# isn’t defined.
However if I remove the sefurls script there is no issue. Any Idea?
Derek said,
11.14.07 at 7:05 am
@james
Is your form method value “post” or “get” and is your action page using the respective scope?
Jason said,
11.18.07 at 9:37 am
I’ve noticed something weird with this script on IE 6. I occasionally get an error report where the page fails because for some reason IE 6 is some how loading the favicon.ico as a parameter even though I deleted it.
PATH_INFO: /cID/favicon.ico
Any suggestions?
Thanks!
James said,
02.12.08 at 8:00 am
@derek:
The form uses the post method, and the SEFurls is included in my application.cfm file.
Al said,
02.18.08 at 8:04 pm
Hello,
I tried your script and it works except for my webpage template logo/images don’t show up. Any suggestions???
ogletree said,
02.21.08 at 9:38 pm
I”m not a pro CF programmer. I just do searches on google to get syntax. I’m good at getting small things done with programming languages but nothing very complex. You could post your problem on a CF forum.
James said,
02.26.08 at 10:57 am
@derek:
is your action page using the respective scope?
I don’t quite understand what you’re meaning by this…
Chad said,
03.20.08 at 5:32 am
Thanks for the post. When I dropped this into my application.cfc it killed my css. Any thoughts?
penis enlargement said,
05.10.08 at 2:52 pm
Penis enlargement treatments, solutions and natural herbal medicines to enlarge your penis naturally like 2-3 inches gain in penis size without any hesitation, worries and side effects for making your life more pleasureable and excited. www.penissizeenlargement.net