# Links outside rails application

**URL:** <https://www.ruby-forum.com/t/links-outside-rails-application/114952>\
**Category:** Rails\
**Created:** [September 19, 2007, 7:39am UTC](https://www.ruby-forum.com/t/links-outside-rails-application/114952 "2007-09-19T07:39:40Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![gga](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/b487fb/32.png) [@gga](https://www.ruby-forum.com/u/gga)\
**Post date:** [September 19, 2007, 7:39am UTC](https://www.ruby-forum.com/t/links-outside-rails-application/114952/1 "2007-09-19T07:39:40Z")

</div>

I have a rails application I am developing and there’s basically a  
minor thing I would like to do that makes my development a little bit  
of a pain.  
I’m currently doing my local development using ruby’s webrick. I’m  
also relative new to web development, so pardon my ignorance, too.

Basically, my website has a menu system using CSS that is common to  
all of its web pages, including the rails web pages. This is to allow  
the user to jump from the rails “store” to any other part of the web-  
site (home page, etc). Those external web pages are not inside the  
rails directory.

Thus, all my pages have the menu embedded in them, like:

```
  <li class="top p1"><a href="index.html" class="top">Home</a></

```

li\>

In rails, the views/layouts/\*.rhtml pages have a similar menu embedded  
in them.

What’s bothering me is that within rails those links cannot be  
relative as they are in the rest of my website, as any relative path  
takes me to localhost:3000/relative\_path, instead of the root of my  
website. The problem seems to happen both during development and  
also deployment.

I was wondering if there was an easy way to keep the paths relative,  
but make sure the web server knows they are relative to a certain root  
directory and not the rails’ public root directory.

---

<div class="post-metadata">

**Author:** ![gga](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/b487fb/32.png) [@gga](https://www.ruby-forum.com/u/gga)\
**Post date:** [September 19, 2007, 8:30am UTC](https://www.ruby-forum.com/t/links-outside-rails-application/114952/2 "2007-09-19T08:30:44Z")

</div>

gga wrote:

> rails directory.  
> relative as they are in the rest of my website, as any relative path  
> takes me to localhost:3000/relative\_path, instead of the root of my  
> website. The problem seems to happen both during development and  
> also deployment.
> 
> I was wondering if there was an easy way to keep the paths relative,  
> but make sure the web server knows they are relative to a certain root  
> directory and not the rails’ public root directory.

If you are new to Web server configuration my suggestion is to just make  
them absolute links. If you really really have to have them be relative  
links for some reason you can use something like mod\_rewrite with Apache  
to have the Web server point the links to the proper places.

–  
Michael W.

---

<div class="post-metadata">

**Author:** ![gga](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/b487fb/32.png) [@gga](https://www.ruby-forum.com/u/gga)\
**Post date:** [September 20, 2007, 11:35pm UTC](https://www.ruby-forum.com/t/links-outside-rails-application/114952/3 "2007-09-20T23:35:56Z")

</div>

> If you are new to Web server configuration my suggestion is to just make  
> them absolute links. If you really really have to have them be relative  
> links for some reason you can use something like mod\_rewrite with Apache  
> to have the Web server point the links to the proper places.

Thanks, that’s what I’m doing now but I want to change that, as my  
links will probably be updated often and I want to have something that  
is as bullet-proof as possible.

mod\_rewrite is probably not an option as my site is being hosted and  
not under my full control.

I was wondering if rails’ routes.rb file could also be used for this  
purpose. Ideally I would like to use a regexp to route any links  
pointing to some subdirectory (subdomain).
