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:
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:
maps to

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:
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.

No comments: