# How do URL's like /images/xx get mapped to the correct place

**URL:** <https://www.ruby-forum.com/t/how-do-urls-like-images-xx-get-mapped-to-the-correct-place/97496>\
**Category:** Rails\
**Created:** [July 7, 2006, 1:49pm UTC](https://www.ruby-forum.com/t/how-do-urls-like-images-xx-get-mapped-to-the-correct-place/97496 "2006-07-07T13:49:24Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![ewildgoose](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/bcef8e/32.png) [@ewildgoose](https://www.ruby-forum.com/u/ewildgoose)\
**Post date:** [July 7, 2006, 1:49pm UTC](https://www.ruby-forum.com/t/how-do-urls-like-images-xx-get-mapped-to-the-correct-place/97496/1 "2006-07-07T13:49:24Z")

</div>

In the default routing file there is nothing about the /images/ URL, or  
the /javascript/ urls.

…So where is the code which makes these special URLs work?

Cheers

Ed W

---

<div class="post-metadata">

**Author:** ![ewildgoose](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/bcef8e/32.png) [@ewildgoose](https://www.ruby-forum.com/u/ewildgoose)\
**Post date:** [July 7, 2006, 4:32pm UTC](https://www.ruby-forum.com/t/how-do-urls-like-images-xx-get-mapped-to-the-correct-place/97496/2 "2006-07-07T16:32:09Z")

</div>

There is no code needed to make these work, as all requests look in the  
public folder first. If nothing is found (404), then the request goes  
through Rails.

---

<div class="post-metadata">

**Author:** ![ewildgoose](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/bcef8e/32.png) [@ewildgoose](https://www.ruby-forum.com/u/ewildgoose)\
**Post date:** [July 7, 2006, 5:53pm UTC](https://www.ruby-forum.com/t/how-do-urls-like-images-xx-get-mapped-to-the-correct-place/97496/3 "2006-07-07T17:53:27Z")

</div>

Brian H. wrote:

> If nothing is found (404), then the request goes through Rails.

Actually that kind of depends upon how your Web server is configured.  
You’re quite right that there’s nothing particularly special about the  
URLs, though.

> > …So where is the code which makes these special URLs work?

Some people configure their Web server so that the Rails application’s  
“public” folder is the document root for the Web; then “/images/…”  
works just like any conventional URL, fetching a file from that document  
root. In such a case it often makes sense, if the Web server supports  
it, to have a “not found” document set up that’s actually one of the  
Rails dispatch.xyz files. Then things work exactly as Brian said.

Other people put their Rails application somewhere outside the document  
root for the Web server, often for security reasons. It’s common to  
create a symbolic link in the Web server part of the filesystem to the  
Rails ‘public’ directory in such a case. The use of a “not found”  
handler to run the Rails dispatcher may still apply; or in some cases,  
using URL rewriting to get the dispatcher to execute can be useful.  
Rails applications’ config/routes.rb files help reduce or eliminate the  
need for URL rewriting once the application is running, but they don’t  
eliminate the need for it (sometimes) to get the dispatcher kicked off  
in the first place, be it FastCGI or ‘slow’ CGI.

A more complex case occurs when you want a Rails application to exist  
away from the document root, in a subdirectory. Perhaps you want more  
than one Rails application running at once in one single domain - you’re  
unable or unwilling to put each one under a virtual domain. In this case  
the connections between Rails URLs, image URLs etc. and physical file  
locations can get quite abstract but funamdentally the same basic  
approaches of symbolic linking, Not Found handlers or rewriting seem to  
underpin the majority of installations.

---

<div class="post-metadata">

**Author:** ![ewildgoose](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/bcef8e/32.png) [@ewildgoose](https://www.ruby-forum.com/u/ewildgoose)\
**Post date:** [July 7, 2006, 7:30pm UTC](https://www.ruby-forum.com/t/how-do-urls-like-images-xx-get-mapped-to-the-correct-place/97496/4 "2006-07-07T19:30:32Z")

</div>

Hi

> Actually that kind of depends upon how your Web server is configured.  
> You’re quite right that there’s nothing particularly special about the  
> URLs, though.

…

Aha, I see. That makes more sense now.

Cheers

Ed W
