[Frank] How can I access the domain name in routes.rb?

I am trying to setup an application where the URLs must be of the format

  1. sub.domain.com/sub/category
    and
  2. sub.domain.com/search/something

In the first path the first part of the subdomain must match the
folder name.

I tried to use request.domain(2) to get the domain information but
keep getting errors.

I was thinking that may be I can setup regexp to math the subdomain
name with the folder but to no avail.

My questions are:
How can I setup the proper routes for these URLs?
How can I access the domain name in routes.rb?

Thanks

Frank