Flexible Friendly URLs for Farcry with Mod rewrite
This alternative method uses apache's mod_rewrite functionality to dynamically rewrite the url before passing it to ColdFusion. This example uses the exact same format as the FU servlet so it should be possible to drop it into place.
So without further ado - here is what you do.
Put this in the virtual host section of your apache config:
RewriteCond %{REQUEST_METHOD} ^(TRACE|TRACK)
RewriteRule .* - [F]
RewriteRule ^/go([^\?]*)(?:\?(.*))? /go.cfm\?path=/go$1&$2 [PT,L,QSA]
Advantages
- Simple to change the prefix: i.e. /go/ or use multiple different ones
- Can add additional parameters
- Moves the load from java to apache, which is easier to scale
Disadvantages
- Not available on IIS - which isn't really a disadvantage :-)
Here's and example of some of the flexibility: Multiple working urls which pass a parameter - /ie/ add language=ie and /en/ adds language=en
RewriteRule ^/ie([^\?]*)(?:\?(.*))? /go.cfm\?path=/go$1&$2&language=ie [PT,L,QSA]
Hope it helps, and love to hear your thoughts or comments.
Updated - changed regex to always use the start of the url - see related article.
Update 2 - another fix to the regex - see related article




As much as some do not like it, IIS is a very stable and commonly used web server. Unlike PHP development, it is fairly easy to make CF apps cross-platform compatible and I believe that is a significant advantage CF developers should take full advantage of.
There are alternatives to SES URLs in CF for IIS, including doing it natively in CF, using URL Rewrite (http://www.iismods.com/url-rewrite/index.htm, I have not used this so I cannot speak for it), and others.
I have to say I agree with you - I was just being faecetious.
I'm glad to see that there is a open source solution for URL rewriting on IIS - last time I looked there wasn't (or I could find one 5 years ago).
Thanks for reading,
Mark
Actually there are plugins for IIS that do mod rewrites (and you can use similar RegEx syntax) and they work with FarCry (see wiki link below).
The mod_rewrite that comes with Apache 2.x is a plugin that comes pre-installed Apache (and has for some time).
But wait, is it possible to use a rewrite tool in IIS without having to install a third-party plugin? Microsoft has said for quite a while now that the next version of Windows server will have an officially supported pre-built rewrite plugin (but I haven't looked into it myself).
For more tutorials on using mod rewrite (for both IIS and Apache) for use with FarCry checkout the FarCry Wiki:
http://docs.farcrycms.org:8080/confluence/display/...
Jeff, I am pretty certain you are doing the same thing natively in CF when you use this method, but correct me if I am wrong:http://www.adobe.com/cfusion/knowledgebase/index.c...
My single biggest problem with IIS is the fact that you can't run a development environment on your workstation very easily if you are using IIS. As far as I recall you can only have a single website on and XP machine using IIS. How many web developers do you know that only develop one website? http://channel9.msdn.com/ShowPost.aspx?PostID=2343...
That's why I switched to using apache on windows and then to apache on linux - as I could set up my development environments to match my production ones very simply. And I only have to edit a text file instead of the magical mystery metabase.
Cheers,
Mark
Save the following lines to a text file:
This assumes default setup with IIS and example files:
C:\Inetpub\AdminScripts\adsutil.vbs create_vserv W3SVC/2
C:\Inetpub\AdminScripts\adsutil.vbs copy W3SVC/1 W3SVC/2
Open IIS Management console >>
click on the Web Sites folder Icon >>
right click on your web Default folder (or whatever its named) >>
select Properties >>
enable Logging (if not already logging, this is just temporary) >>
select Properties next to the Active Log Format >> make a note of the log directory name
we just want the directory name which most likely will be W3SVC1 but... just to be safe make a note of the directory name >>
Cancel (uncheck logging enabled if it was unchecked before) >>
close the Properties window >>
select Windows Start >>
select Run >>
copy line 1 of your text file and paste in Run text box >>
hit OK.. you now created a new web site >>
copy line 2 of your text file into the Run text box >>
hit OK .. you now have copied your configuration from the existing site to the new web site. It is now an exact duplicate of the original default web site.
ALMOST DONE!!
Tab back to your IIS Management Console and you should now see two website Folders with the exact names except one will be running and one will be stopped Right click on the stopped web Folder Icon and select Rename site >>
Enter a new name >>
Go to Properties on the newly named site and set a new home directory and save (I keep all of my different project folders on my dev machine under wwwroot just to make it easy but it shouldn't matter). >>
Right Click on the the current running site and select STOP >>
Right Click on the new site and select Start >>
in your browser go to http://127.0.0.1 and your new site should come up. >>
You can edit your Host file >>
Windows Start >> Run >>
paste the following: %WINDIR%\system32\drivers\etc\hosts >>
OK >>
Select Notepad/Wordpad and add an entry to the file like: 127.0.0.1 newSite save >>
In your browser go to http://newSite and the site should work.
NOTE: keep track with your text file on what site you copied and the last site made. Next site you make should be:
C:\Inetpub\AdminScripts\adsutil.vbs create_vserv W3SVC/3
C:\Inetpub\AdminScripts\adsutil.vbs copy W3SVC/1 W3SVC/3
Save the text file.
Easy thing is to create a template website and use this one to build all your new ones.
Good Luck
Robb
Thanks for that - it's good to know it can be done. I'll stick with Apache though - it makes it so much easier to have them as many sites running as you want. It also means you can cut and paste to create new websites.
Cheers,
Mark
Robb
Why is there any need to change your hosts file - just add every site in with the same ip address and you'll be right - or are you using the domain names for something else?
Cheers,
Mark