Skip to main content
Inspiring
January 13, 2010
Question

Url Pattern

  • January 13, 2010
  • 2 replies
  • 828 views

Hello,


I see some sites like "www.?????.com/clients.cfm" being displayed as "www.?????.com/clients"

How can this be done using CF8 MX?

I know that for url from a folder www.?????.com/clients/index.cfm can be displayed as www.??????.com/clients/

But to display as "www.?????.com/clients" is giving me a headache to figure out.


Thanks

    This topic has been closed for replies.

    2 replies

    Inspiring
    January 14, 2010

    Try consulting the documentation for your web server or googling.  The technique you want to use is called "URL rewriting".

    http://en.wikipedia.org/wiki/URL_rewriting

    Owainnorth
    Inspiring
    January 15, 2010

    As pointed out by Bob there, if you were being really hardcore about this you should really do it at the webserver level, before the request even gets to Coldfusion.

    If you're on an Apache server you'll need to use MOD_REWRITE, if you're on Windows IIS you can use a filter called ISAPI_REWRITE or IIS7 has its own built-in engine for it.

    The syntax looks like random scribbling at first, but it's not too hard to get your head around.

    Owainnorth
    Inspiring
    January 13, 2010

    It's actually a little more complicated than you'd hope, so I won't bother going into details.

    The way I do this is by using the onMissingTemplate() method in Application.cfc. Allow this to be called, then use the CGI scope to try and figure out what page you think they're after. You can then do a case statement around it, ie:

    (pseudo)

    -- get the last part of the URL they tried to call

    cfswitch ListLast(CGI.SCRIPT_NAME,"/")

       case "mypage"

         cfinclude mypage.cfm

       case "otherpage"

          cfinclude otherpage.cfm

        defaultcase

          cflocation 404.cfm statuscode=404

    /cfswitch

    It's not particularty simple to do and if you want it working sitewide isn't really that straightforward I'm afraid. Hope that helps a little.

    O.