29 April 2009

directory and sub directorys

This is actually kinda fun little bit of code, i quite liked it, times like this make you glad to be a l33t cf c0der.

Say you want to put something in a sub-directory of your current directory. Expland path function works great but it tags the filename on the end. Sure you could do some funky string functions to strip the filename and then add it back on after...but that's not nearly as fun!


<cfset LocalPath = ExpandPath("customSSL.css") />

<cfset LocalPath = getDirectoryFromPath(LocalPath) & "parsed\" &

listLast(localPath,"\") />

01 April 2009

Friendly URLs and Web Servers

OK so recently needed to produce a method of getting friendly URL's out there. Tried a bunch of things but nothing worked well, it needed to be easy to expand and not require constant changes to load balances / code etc.
Seemed like Adobe had the perfect solution in:
www.adobe.com/go/*
So anything after the go url would get mapped to wherever you wanted.

I came up with 2 solutions for this:

1) Work with ColdFusion, although this solution is wicked awesome i think it may only be appropriate if you're using tomcat or cf itself as your web server.

- Create a java servlet which strips everything after the /go/ keyword and add it as a variable. This servlet must then forward the client to a new set location. In my case i created a go.cfm file inside the application framework i was using. (i also set this location to be read from file so it's not hardcoded)

- edit your WEB-INF/web.xml file in your webserver add a new servlet definition and map it to your servlet

- have the go.cfm file query the database (or whatever you want) for the url param so for example:
www.myurl.com/go/parisHilton
maps to
www.myurl.com/index.cfm?fuseaction=home.celebrities&name=paris=fname=hilton

Have the go.cfm do another redirect.

There is also a way to do this in IIS:

1) Create a directory in webroot called go
2) Open up IIS
3) Right click on the go directory in IIS and click properties
4) Under the directory tab change the selection to “A redirection to a URL”
5) Enter the url:
webpath/appname/go.cfm?Urlvar=
6) None of the check boxes should be checked (I don’t know what they do anyways)

As you can see IIS uses the same go.cfm method, it just doesn't use the java servlet as IIS is not java dependent.

Hope this helps.