# Setting up routes with formats and parameters that are domain names

**URL:** <https://www.ruby-forum.com/t/setting-up-routes-with-formats-and-parameters-that-are-domain-names/171746>\
**Category:** Rails\
**Created:** [July 8, 2009, 4:24pm UTC](https://www.ruby-forum.com/t/setting-up-routes-with-formats-and-parameters-that-are-domain-names/171746 "2009-07-08T16:24:01Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dan\_Van\_Derveer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/59ef9b/32.png) [@Dan\_Van\_Derveer](https://www.ruby-forum.com/u/Dan_Van_Derveer)\
**Post date:** [July 8, 2009, 4:24pm UTC](https://www.ruby-forum.com/t/setting-up-routes-with-formats-and-parameters-that-are-domain-names/171746/1 "2009-07-08T16:24:01Z")

</div>

## Configuration

This is on Rails 2.3.2.1 running on ruby 1.8.4

## in config/routes.rb

map.somecontroller\_show ‘somecontroller/:id.:format’,  
:requirements =\> {:id =\> /\w[^/?;]\*/ },  
:controller =\> ‘somecontroller’, :action =\> ‘show’,  
:conditions =\> { :method =\> :get }

## the problem

:id for this controller is a domain name. The path to this route will  
look like this:  
GET /somecontroller/somehost.mydomain.com.xml - for when the user  
wants a specific format  
or  
GET /somecontroller/somehost.mydomain.com - for when the user requests  
the default format

For the first path params should be {:action =\> ‘show’, :controller =\>  
‘somecontroller’, :id =\> ‘[somehost.mydomain.com](http://somehost.mydomain.com)’, :format =\> ‘xml’}  
but end up being {:action =\> ‘show’, :controller =\>  
‘somecontroller’, :id =\> ‘somehost.mydomain.com.xml’}

For the second path params should be {:action =\> ‘show’, :controller  
=\> ‘somecontroller’, :id =\> ‘[somehost.mydomain.com](http://somehost.mydomain.com)’} and work  
properly.

The problem is with this route I can not extract the format because it  
is getting matched by the :id regular expression. I could change  
the :id regular expression to be not greedy which will fix the first  
path but break the second one because it will extract ‘com’ as the  
format.

How do you use :format when your URI contains domain names?

I’ve hit this issue while upgrading from Rails 2.1.2 to 2.3.2.1.  
Historically my site has just had two routes, one for the route with  
format and one without.
