Regular Expression N00b

Topics: User Forum
Feb 2, 2010 at 4:54 AM

Never used IIRF before and spent five hours today getting it setup on my development CF9 server (I know I'm pathetic, but apparently I had it running the whole time and couldn't figure out how to run the test... my own dumb fault).  Glad I learned it though... got IIRF up and running on my live server in less than ten minutes.

I'm trying to pickup on regular expressions and slowly grasping things.  So I thought I'd outline what I'm trying to do and see what an expert here can come up with.

I'd like:

http://www.domain.com/index.cfm?company=companyName

to be rewritten as:

http://www.domain.com/companyName

where companyName is unique, always a one word variable (not a numeric, but the name may contain numerals) and is not case sensitive.

Thanks in advance!

Coordinator
Feb 2, 2010 at 9:01 PM

Trty this:

## incoming: http://server/companyName
##    rewrite to:  http://server/index.cfm?company=companyName
RewriteRule ^/([^/]+)$   index.cfm?company=$1

That sequence -- ([^/]+) -- captures any url path that has exactly one segment. Break it down:

  • the square brackets [ ] denote a range of characters.
  • The ^/ inside the square brackets says "any character except slash".
  • the + is a quantifier that says "one or more".
  • The parens denote a capturing group.

Wrap it all up and it is: a sequence of one or more characters, none of which is a slash.

Then, the replacement string just puts whatever is captured by that regex, as the first named query string param, using the name "company".