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

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

June 21st, 2007 ogletree

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:
  1. June 22nd, 2007 at 14:21 | #1

    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.

  2. bayouboy7303
    June 27th, 2007 at 15:43 | #2

    Is it still necessary to remove the “?” and other symbols from CF code so search engines can read them?
    Thanks!

  3. June 27th, 2007 at 20:43 | #3

    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.

  4. Joe
    August 22nd, 2007 at 08:12 | #4

    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.

  5. October 23rd, 2007 at 00:53 | #5

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

  6. James
    October 25th, 2007 at 07:52 | #6

    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?

  7. November 14th, 2007 at 07:05 | #7

    @james

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

  8. Jason
    November 18th, 2007 at 09:37 | #8

    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!

  9. James
    February 12th, 2008 at 08:00 | #9

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

  10. February 18th, 2008 at 20:04 | #10

    Hello,

    I tried your script and it works except for my webpage template logo/images don’t show up. Any suggestions???

  11. February 21st, 2008 at 21:38 | #11

    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.

  12. James
    February 26th, 2008 at 10:57 | #12

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

  13. Chad
    March 20th, 2008 at 05:32 | #13

    Thanks for the post. When I dropped this into my application.cfc it killed my css. Any thoughts?

  14. June 18th, 2008 at 13:30 | #14

    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.

  15. Usman
    August 9th, 2008 at 06:00 | #15

    Guys,

    Sorry I might be asking the obvious here but am I supposed to add something else with this code for it to work? when I added this code to my application.cfm file it just gave me a flat 404 error.

    I’m new to this so some guidance would be much appreciated.

    Thanks.

  16. August 13th, 2008 at 23:58 | #16

    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.

  17. LA
    December 5th, 2008 at 08:26 | #17

    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?

  18. March 20th, 2009 at 10:00 | #18

    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

  19. AlexW
    June 26th, 2009 at 18:51 | #19

    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?

  20. Eliot
    October 12th, 2010 at 14:59 | #20

    Thanks for sharing this script. It’s the only one of 3 that I’ve seen that I’ve been able to get working.

    However I’d like to make my URL a bit easier on the eyes and fingers. I get this:

    http://www.example.com/properties/details.cfm/ProductID/448

    is there a way to get the details.cfm to read just details or better yet how about:

    http://www.example.com/properties/ProductID/448

    ?

    Thanks,

    Eliot

  21. October 12th, 2010 at 15:09 | #21

    Is there a fix to preserve parameters that are passed on the end of links throughout the site?

    I see there is some discussion about forms but nothing on links….

    thanks!

  22. October 13th, 2010 at 11:14 | #22

    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.

  23. November 23rd, 2010 at 04:01 | #23

    Thanks for your work over time,. I have enjoyed following this blog and reading your work. I wish you the best success now and in the future at whatever you put your hands to do.

    Thanxs
    Search Engine Marketing

  24. CFer
    January 18th, 2011 at 04:20 | #24

    @Eliot
    Did you find the answer to your question ? coz I’m having the same prb and looking for a solution…
    Thanks

Comments are closed.