# Eliminate leading-directory name from URL's

**URL:** <https://www.ruby-forum.com/t/eliminate-leading-directory-name-from-urls/130613>\
**Category:** Rails\
**Created:** [February 29, 2008, 9:08pm UTC](https://www.ruby-forum.com/t/eliminate-leading-directory-name-from-urls/130613 "2008-02-29T21:08:37Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![inari](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/838e76/32.png) [@inari](https://www.ruby-forum.com/u/inari)\
**Post date:** [February 29, 2008, 9:08pm UTC](https://www.ruby-forum.com/t/eliminate-leading-directory-name-from-urls/130613/1 "2008-02-29T21:08:37Z")

</div>

Hello,

Is there a way to get Rails to ignore a leading-directory in a URL  
(either in the environment.rb or routes.rb file)?

For example, I’d like all requests to: [http://domain.com/blah/products](http://domain.com/blah/products)  
to get processed as [app]/products

I don’t have access to use mod\_redirect, and right now Rails keeps  
looking at “blah” to be a controller. I’d simply like it always  
stripped out of the URL.

Any suggestions? Thank you!

-Jason

---

<div class="post-metadata">

**Author:** ![inari](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/838e76/32.png) [@inari](https://www.ruby-forum.com/u/inari)\
**Post date:** [February 29, 2008, 9:29pm UTC](https://www.ruby-forum.com/t/eliminate-leading-directory-name-from-urls/130613/2 "2008-02-29T21:29:54Z")

</div>

that’s not a leading directory, it’s the rails routing path which  
follows the convention :controller/:action/:id. Say you were to strip  
out the controller portion and all you have are actions, which  
controller will these actions execute in? And what if you have two  
controllers with the same name, how will rails disambiguate between  
the two actions. Or say you wanted to get rid of the action name and  
just have a controller name? Then what action should be called?

If you want to use the format:

[myapp.com/products](http://myapp.com/products) (shows index page)  
[应用宝官网-全网最新最热手机应用游戏下载](http://myapp.com/products/1) (shows details for product with id 1)  
[myapp.com/products/1/edit](http://myapp.com/products/1/edit) (shows edit screen for product with id 1)

then look into using restful routes.

Mike

---

<div class="post-metadata">

**Author:** ![inari](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/838e76/32.png) [@inari](https://www.ruby-forum.com/u/inari)\
**Post date:** [February 29, 2008, 11:28pm UTC](https://www.ruby-forum.com/t/eliminate-leading-directory-name-from-urls/130613/3 "2008-02-29T23:28:50Z")

</div>

Jason C. wrote:

> Hello,
> 
> Is there a way to get Rails to ignore a leading-directory in a URL  
> (either in the environment.rb or routes.rb file)?

> Any suggestions? Thank you!
> 
> -Jason

in your config/routes.rb

map.connect ‘blah/:controller/:action/:id’

hth

ilan
