≡ Menu

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>

[tags]coldfusion, cold fusion, CFML, seo, url, Search Engine Friendly URL’s, google, search engine[/tags]

{ 16 comments… add one }

  • DazzlinDonna June 22, 2007, 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.

  • ogletree June 27, 2007, 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.

  • Joe August 22, 2007, 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 October 23, 2007, 12:53 am

    […] Hello
    Great resource! I’ve been meaning to do a similar post. It’s interesting.
    Alex Bell […]

  • James October 25, 2007, 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 November 14, 2007, 7:05 am

    @james

    Is your form method value “post” or “get” and is your action page using the respective scope?

  • James February 12, 2008, 8:00 am

    @derek:
    The form uses the post method, and the SEFurls is included in my application.cfm file.

  • Al February 18, 2008, 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 February 21, 2008, 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 February 26, 2008, 10:57 am

    @derek:
    is your action page using the respective scope?
    I don’t quite understand what you’re meaning by this…

  • Bob L. June 18, 2008, 1:30 pm

    Guys,
    This is a path issue. The script is modifying the base path.

    A simple, but dirty, fix is to use absolute URL’s when referencing your images, css, scripts, etc.

    This isn’t an ideal solution, but the SEF URL’s isn’t ideal either. If you are on your own windows box, try ISAPI rewrite.

    Good luck.

  • ogletree August 13, 2008, 11:58 pm

    It has been a while since I wrote this and have not worked with cold fusion since. I wish I had made documentation. Sorry. I don’t work with that client any more and don’t have access to a coldfusion server to tetst.

  • LA December 5, 2008, 8:26 am

    what happens when someone copies the new url, sends it to a friend, and then the friend clicks the link? wouldn’t you need to reverse your logic in that situation in order for the url to work?

  • Adam March 20, 2009, 10:00 am

    I am interested in this too. I generally take the position that Google has “figured out” how to deal with the ‘?’. So I don’t *think* there is any SEO value either way any more. I think that once upon a time, the ? was considered dirty. But not really anymore.

    BUT – I do think there is a user experience issue. And also, as mentioned above, there is the emailing issue. Also, I’ve seen issues submitting url’s with ? and & into certain bookmarking sites. It would still be nice to make it go away. Is this possible in CF?

    Thx

  • AlexW June 26, 2009, 6:51 pm

    Google seems to read “?” okay in URL, but to my understanding, page rank doesn’t flow too well from the main page to the sub-directory if there is ? in it?

  • Eliot October 13, 2010, 11:14 am

    Ok so I see that if I add the same code to the pages the are being linked the problem is fixed.

    Still wondering if I could get a cleaner URL without the ” .cfm ” as a folder name.

Leave a Comment