# Fix URL redirecting

**URL:** <https://www.ruby-forum.com/t/fix-url-redirecting/85063>\
**Category:** Rails\
**Created:** [February 9, 2007, 6:28pm UTC](https://www.ruby-forum.com/t/fix-url-redirecting/85063 "2007-02-09T18:28:06Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [February 9, 2007, 6:28pm UTC](https://www.ruby-forum.com/t/fix-url-redirecting/85063/1 "2007-02-09T18:28:06Z")

</div>

I tried posting this once but had problems with Google G…

Hi,  
I watched the rails screencast on creating a blog in 15 minutes.  
I followed along got it working on my home PC and I then uploaded it  
to my web host. So I have,

/home//blog

I had to change some config in the blog app (i.e. production mode,  
db settings).

I then created a directory…

cd ~/public\_html/bor

And a symlink to point to my blog app…

ln -s ~/blog/public ~/public\_html/bor

I deleted the blog/public/index.html and I modified blog/config/  
routes.rb to contain the following line:

map.connect ‘’, :controller =\> ‘blog’, :action =\>‘index’

I did that so when someone goes to [mysite.com/bor/](http://mysite.com/bor/) they would get  
directed to what is the index action in my blog\_controller.

Ok, so things are working and I can see my blog posts when I go to,  
[mysite.com/bor/](http://mysite.com/bor/) Now if I click on post I get redirected to  
[mysite.com/bor/blog/show/1](http://mysite.com/bor/blog/show/1) …and from that page if I click “back”  
I end up at [mysite.com/bor/blog/list](http://mysite.com/bor/blog/list) …basically all the links look  
like [mysite.com/bor/blog/](http://mysite.com/bor/blog/) instead of what I hoped to  
see, [mysite.com/bor/](http://mysite.com/bor/).

Any ideas?

If it helps, my blog\_controller.rb has the following method for the  
“index” …

def index  
list  
render :action =\> ‘list’  
end  
Thanks!

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [February 9, 2007, 7:53pm UTC](https://www.ruby-forum.com/t/fix-url-redirecting/85063/2 "2007-02-09T19:53:15Z")

</div>

craig w wrote:

> I tried posting this once but had problems with Google G…
> 
> Hi,  
> I watched the rails screencast on creating a blog in 15 minutes.  
> I followed along got it working on my home PC and I then uploaded it  
> to my web host. So I have,
> 
> /home//blog
> 
> I had to change some config in the blog app (i.e. production mode,  
> db settings).
> 
> I then created a directory…
> 
> cd ~/public\_html/bor
> 
> And a symlink to point to my blog app…
> 
> ln -s ~/blog/public ~/public\_html/bor
> 
> I deleted the blog/public/index.html and I modified blog/config/  
> routes.rb to contain the following line:
> 
> map.connect ‘’, :controller =\> ‘blog’, :action =\>‘index’
> 
> I did that so when someone goes to [mysite.com/bor/](http://mysite.com/bor/) they would get  
> directed to what is the index action in my blog\_controller.
> 
> Ok, so things are working and I can see my blog posts when I go to,  
> [mysite.com/bor/](http://mysite.com/bor/) Now if I click on post I get redirected to  
> [mysite.com/bor/blog/show/1](http://mysite.com/bor/blog/show/1) …and from that page if I click “back”  
> I end up at [mysite.com/bor/blog/list](http://mysite.com/bor/blog/list) …basically all the links look  
> like [mysite.com/bor/blog/](http://mysite.com/bor/blog/) instead of what I hoped to  
> see, [mysite.com/bor/](http://mysite.com/bor/).
> 
> Any ideas?
> 
> If it helps, my blog\_controller.rb has the following method for the  
> “index” …
> 
> def index  
> list  
> render :action =\> ‘list’  
> end  
> Thanks!

uh huh…

simplest solution rename blog controller to bor controller and move it  
up a directory

then read agile development in rails by the pragmatic programmers group.

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [February 9, 2007, 8:21pm UTC](https://www.ruby-forum.com/t/fix-url-redirecting/85063/3 "2007-02-09T20:21:21Z")

</div>

> uh huh…
> 
> simplest solution rename blog controller to bor controller and move it  
> up a directory

…I am reading the agile book now (is there a certain section you  
recommend for more information?).

Anyways, what do you mean by “move it up a directory”? Move the  
bor\_controller somewhere? The controller is kept in app/controllers,  
sorry just not understanding what you mean.

Thanks for the help though.

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [February 9, 2007, 8:47pm UTC](https://www.ruby-forum.com/t/fix-url-redirecting/85063/4 "2007-02-09T20:47:44Z")

</div>

craig w wrote:

> …basically all the links look  
> like [mysite.com/bor/blog/](http://mysite.com/bor/blog/) instead of what I hoped to  
> see, [mysite.com/bor/](http://mysite.com/bor/).
> 
> Any ideas?

That because it’s all going through the ‘blog’ controller. If you have  
other controllers, your url would look like:

/bor/comments/show/1  
/bor/products/new

You can setup a custom route that looks like:

map.blog ‘:action/:id’,  
:controller =\> ‘blog’

Now you can do:

url\_for(:controller =\> ‘blog’, :action =\> ‘show’, :id =\> 123)

Or even better:

blog\_url(:action =\> ‘show’, :id =\> 123)

and get the url:

/bor/show/123

Just keep in mind that if you do add more controllers in the future  
rails routing will have a hard time figuring out what goes to the blog  
controller and what goes to the other controllers. This is why its best  
to keep controller names in the url.

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [February 10, 2007, 5:41am UTC](https://www.ruby-forum.com/t/fix-url-redirecting/85063/5 "2007-02-10T05:41:38Z")

</div>

…bump…

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [February 9, 2007, 9:00pm UTC](https://www.ruby-forum.com/t/fix-url-redirecting/85063/6 "2007-02-09T21:00:23Z")

</div>

> That because it’s all going through the ‘blog’ controller. If you have  
> other controllers, your url would look like:
> 
> /bor/comments/show/1  
> /bor/products/new

so can I get rid of “bor” altogether and somehow make my blog  
application accessible, even though it is stored at,

/home//blog

?

I’d prefer not to even have the “bor” and symlink…but I didn’t know  
how else to expose blog/public to the web.

Thanks.
