# Custom url's and routing

**URL:** <https://www.ruby-forum.com/t/custom-urls-and-routing/144280>\
**Category:** Rails\
**Created:** [July 28, 2008, 6:55am UTC](https://www.ruby-forum.com/t/custom-urls-and-routing/144280 "2008-07-28T06:55:40Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![nahabed](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/b77776/32.png) [@nahabed](https://www.ruby-forum.com/u/nahabed)\
**Post date:** [July 28, 2008, 6:55am UTC](https://www.ruby-forum.com/t/custom-urls-and-routing/144280/1 "2008-07-28T06:55:40Z")

</div>

I’m working on a Rails 2.0 app… we’re getting read to use AdWords to  
drive some traffic… we plan to use a custom URL per ad (to allow us  
to track conversions on Google Analytics). The site is an ecommerce  
site. The plan is to route the adds to the same today page (and then  
track through to conversion or not).

So I’d like ad-1 to use the URL [www.foobar.com/ad1](http://www.foobar.com/ad1), ad-2 to use  
[www.foobar.com/ad2](http://www.foobar.com/ad2), and so on. Where all the /adX url’s point to  
[www.foobar.com](http://www.foobar.com) which is the welcome page.

I know that routes.rb is the way to go but wondering what the elegant  
solution is here 🙂

thanks!

---

<div class="post-metadata">

**Author:** ![nahabed](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/b77776/32.png) [@nahabed](https://www.ruby-forum.com/u/nahabed)\
**Post date:** [July 28, 2008, 6:46pm UTC](https://www.ruby-forum.com/t/custom-urls-and-routing/144280/2 "2008-07-28T18:46:16Z")

</div>

> I know that routes.rb is the way to go but wondering what the elegant  
> solution is here 🙂

map.ad /:ad/, :requirements =\> {:ad =\> /ad\d+/}

Put that just above the default route.

If it were me, I’d do it this way just to isolate everything under ‘ad’:

/ad/1  
/ad/2  
/ad/3

with a route of:

map.ad /ad/:id, :controller =\> ‘home’, :action =\> ‘index’

(assuming home and index are correct for your home page)

-philip

---

<div class="post-metadata">

**Author:** ![nahabed](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/b77776/32.png) [@nahabed](https://www.ruby-forum.com/u/nahabed)\
**Post date:** [July 29, 2008, 5:09am UTC](https://www.ruby-forum.com/t/custom-urls-and-routing/144280/3 "2008-07-29T05:09:00Z")

</div>

Thanks Philip,

I think the line above has a slight typo in it… the following worked  
for…

map.ad ‘/ad/:id’, :controller =\> ‘home’, :action =\> ‘index’
