Redirecting The Root Of The Website

Hi,

I've looked for several ways of doing this but none of the methods I
have found work correctly.

Basically, the website I am writing is navigated to using the standard
domain name, i.e. http://website.com/. Using the routes.rb file the root
of the website is mapped to a controller called 'home' so
http://website.com/ is the same as http://website.com/home.

I however wish to have users that visit http://website.com/ to be
redirected (in a way the user can see) to http://website.com/home.

I have tried doing this by adding redirect_to to routes.rb, this didn't
work. I have also tried the redirect using .htaccess but unfortunately
my skills in this area are rather limited. I have also tried a plugin
that didn't work correctly.

Can you help me sort this problem out.

Thanks in advance,
Alex

not necessarily the best way, but you can input an index.html in your
public folder and use meta tag to redirect

<head>
<meta http-equiv="refresh" content="0;url=http://…/home">
</heed>
<body>
redirecting you to …/home
</body>

in any case, why not just http://website.com/ ?

Pre Rails 2.0:

map.connect ‘’, :controller => “home”

Rails 2.0

map.root :controller => “home”

Use redirect to call in ur controller.

Http://www.rubyplus.org
Free Ruby & Rails screencasts

Hi,

rubynuby wrote:

not necessarily the best way, but you can input an index.html in your
public folder and use meta tag to redirect

<head>
<meta http-equiv="refresh" content="0;url=http://…/home">
</heed>
<body>
redirecting you to …/home
</body>

in any case, why not just http://website.com/ ?

I didn't want it to be quite that messy, although I suppose it will get
the job done.

Ryan Bigg wrote:

Pre Rails 2.0:

map.connect '', :controller => "home"

Rails 2.0

map.root :controller => "home"

I realize this, but it doesn't really answer the question.

Bcp wrote:

Use redirect to call in ur controller.

Http://www.rubyplus.org
Free Ruby & Rails screencasts

On Feb 16, 2008, at 12:55 PM, Digital Pardoe
<rails-mailing-list@andreas-s.net

I tried redirect but it didn't work, can you give me a little code help,
context etc, or do I just put it anywhere? ;-).

Thanks,
Alex

Did my reply get lost?

map.root :controller => “home”

Stick that in your config/routes.rb file and it’ll do just what you want it to do!

Ryan Bigg wrote:

Did my reply get lost?

map.root :controller => "home"

Stick that in your config/routes.rb file and it'll do just what you want
it
to do!

Erm, your reply didn't get lost, 'map.root' is merely an alias for;

map.connect '', controller => "home"

It still doesn't physically redirect the user so they see
http://website.com/home in their address bar.

I have however given you the benefit of the doubt and tried it, it
didn't work.

Alex

I understand what you want to do but would that confuse the user? If I
went to att.com and then was redirected i would wonder why.
Is this a site someone would log into?

Just curious.

John I

John Ivanoff wrote:

I understand what you want to do but would that confuse the user? If I
went to att.com and then was redirected i would wonder why.
Is this a site someone would log into?

Just curious.

John I

On Feb 17, 8:03�am, Digital Pardoe <rails-mailing-l...@andreas-s.net>

I'm really just after doing if for the sake of consistency, the blog is
accessed by /blog, photos by /photography, so why shouldn't home be
accessed with /home. It may also be something useful to add to my Rails
armory, and might come up again in the future for different purposes.

Thanks,
Alex

someone correct me if i'm really wrong, but i believe that what is
missing from the conversation is this:

when you do something like
map.root, :controller=>"home", :action=>"index" (if you want to
specify action) then you have a new named route, called root

so if you want to go back to the root of the application then what
would be www.mysite.com is actually www.mitesite.com/home...
throughout your app you can then use something like this:

link_to root_path

or link_to root_url

those are nice little guys that will do the named route business for
you. Then you can be nice and DRY and not actually specify your
domain at all, but let your application figure that part out for you.

Is that a help?

Digital Pardoe wrote:

It still doesn't physically redirect the user so they see
http://website.com/home in their address bar.

I have however given you the benefit of the doubt and tried it, it
didn't work.

It makes sense that you don't want two URIs on your site to have
identical content.

Here is a somewhat kludgy way to do this - in routes.rb:

  map.root :controller => 'home', :action => 'redirect'

Then in the home_controller.rb:

  def redirect
    redirect_to url_for(:controller => 'home', :action => 'index')
  end

Mike Mcc wrote:

Digital Pardoe wrote:

It still doesn't physically redirect the user so they see
http://website.com/home in their address bar.

I have however given you the benefit of the doubt and tried it, it
didn't work.

It makes sense that you don't want two URIs on your site to have
identical content.

Here is a somewhat kludgy way to do this - in routes.rb:

  map.root :controller => 'home', :action => 'redirect'

Then in the home_controller.rb:

  def redirect
    redirect_to url_for(:controller => 'home', :action => 'index')
  end

Hi:

1.in Configure/routes.rb

add a command: map.root :controller => "home"

2.delete public/index.html . Or it will not happen.

Cruise