Friendly URL Configuration

You'll need a rewrite engine of some description to get FUs going.

Once you have a rewrite engine in place, the only thing you need to worry about is the config file – ie the rewrite rules themselves.

RewriteRule .*/go/(.*) /go.cfm?path=/go/$1

This assumes that the original URL does not have any url parameters (?name=value&name2=value2...). If it does, they will be placed at the end (in the $1), and now your URL has two ?'s, confusing the url params a bit.

An alternative regular expression if you need params might be:

RewriteRule .*/go(/[^\?]*)(?:\?(.*))? /go.cfm\?path=/go$1&$2

To break that down a little bit further:

([^\?]*)

Regular expression speak for "zero or more non-question mark characters" - This will get the string of the rest of the friendly url path.

(?:\?(.*))?

Regular expression speak for "string of all characters after a question-mark, if any" - This will get the 'query_string'. The extended path gets added to the path url parameter and the query_string is appended, when the appropriate go.cfm is called.

And finally write your rule:

# friendly url rules
RewriteRule ^/go/(.*)$ /go.cfm?path=/go/$1 [L,PT]

Notice the L,PT this tells the web server to deliver the url back to the browser to be displayed in the address bar

Scott Talsma writes..

I documented my pains w/ISAPI rewrite, as I had a fair amount of assistance from different individuals getting it to work on win2003. The integration w/ FarCry is easy; getting it to play w/IIS not so:
http://www.echoeleven.com/blog/index.cfm/2005/11/29/Win2003--ISAPIrewrite

ISAPI Rewrite on Multi-Server J2EE CF Configuration

I was able to get the free Ionic filter working on the single-server install of ColdFusion, but had trouble with it the multi-server configuration. Thus I turned to the ISAPI_Rewrite filter, commercial full version, and using this entry from Brandon Purcell's blog was able to get it working without a problem.
http://www.bpurcell.org/blog/index.cfm?mode=entry&entry=1070

IIRF: Ionic's ISAPI Rewrite Filter

http://cheeso.members.winisp.net/IIRF.aspx

To install you must read the readme file in the download for instructions.

Apache has mod_rewrite, which allows URL rewriting. A URL like http://foo/bar/bam can be translated into http://foo/baz/bam.jsp or http://foo/baz/bam.php or ... anything!

ASP.NET has a URL mapping mechanism, but it works only for filetypes that are handled by ASP.NET: aspx, ascx, asmx, and so on. For static files or non-ASP.NET files, (xml, gif, jpg, css), the ASP.NET mapping won't work cleanly.

IIS, like Apache's HTTP server, has an extension mechanism: it is called the ISAPI filter. There are commercial ISAPI filters that endow IIS with the ability to re-write URLs. This is my own, small, URL rewriting ISAPI filter.

  • It is implemented in C
  • Not implemented with MFC
  • compiles with VS2003 or with the (free) MS VC++ 2003 toolkit.
  • Rewrite rules are specified using regular expressions (provided by the PCRE library).
  • RewriteCond is now supported
  • open source, BSD-style license
  • works with IIS5 and IIS6
  • simple to install

v1.2 includes automatic ini file reloading, without IIS restart. Just modify the file and the filter detects it automatically. Be careful to save only valid ini files!

NB: IIRF does not do redirects. You cannot set up a rule that modifies http://yourserver/something/baz to get rewritten to http://Otherserver/something/baz. Also, IIRF does not do proxy and reverse-proxy.

Apache mod_rewrite

Apache has the mod_rewrite engine automatically built in. However, you will need to ensure that the module has been loaded by checking that this line in httpd.conf is not commented out:

LoadModule rewrite_module modules/mod_rewrite.so

Then you need to update your VirtualHost entry to turn on the RewriteEngine:

RewriteEngine on

And finally write your rule:

# friendly url rules
RewriteRule ^/go/(.*)$ /go.cfm?path=/go/$1 [L,PT]

A complete sample from a local development workstation might look something like this:

Sample From Geoff's Local webDU Install
<VirtualHost *:80>
  ServerName mxdu.gandalf
  DirectoryIndex index.cfm index.htm
  DocumentRoot "e:/webapps/MXDU/www"
  IndexOptions +FancyIndexing
  ServerAdmin modius@daemon.com.au
  ErrorLog "logs/mxdu.gandalf-error_log"
  CustomLog logs/mxdu.gandalf-access_log common
  Alias /scribble e:/webapps/scribble
  Alias /cfdocs e:/webapps/cfdocs
  Alias /CFIDE e:/webapps/htdocs/CFIDE

  #running on p300 FarCry
  Alias /farcry "e:/farcry/p300/farcry_core/admin"

  #enabling rewriting in Apache
  RewriteLogLevel 9
  RewriteLog "e:\webapps\logs\mxdu_rewrite.log"

  RewriteEngine on
  # friendly url rules
  RewriteRule ^/go/(.*)$ /go.cfm?path=/go/$1 [L,PT]

  <Directory "e:/webapps/MXDU/www">
    Options All
  </Directory>
</VirtualHost>

Enabling Friendly URLs in Farcry

Once you've set up your webserver to use either mod_rewrite or IIRF, you'll need to enable Friendly URLs in Farcry.

To do this go to the admin tab with Farcry Admin. Click on "config files" to display the list of configuration files available.

  • Click on the "Plugins" config file. Change the "FU" entry to "Yes" and then "update config".
  • Click on "FUSettings". Change "SES URLS" to "Yes".

You may need to refresh the application using the "Update App" link in the control on the front of the site or add "updateapp=1" to the url for your site and press return to load the page. Once this is done the ability to add and edit friendly urls on types with bFriendly set to true. eg. dmNavigation and dmHTML.