Help getting top level redirect set up with Rails

Help getting top level redirect set up with Rails

Posted by: parki
Posted on: 2006-06-23 05:27:00

Hello!

I have everything working fine, except one minor detail.

My Rails site is up, and you can access is via:

http://www.mydomain.com/controller/action

in the usual way. If you surf to:

http://www.mydomain.com/

I would like to *redirect* to

http://www.mydomain.com/controller/action

so that the user sees the path which is consistent for the rest of the site.

I am flummoxed on how to do this - I have tried altering the .htacess file, but have not been able to figure out a way to do this.

One idea was to put in a 301 redirect rule into my .htaccess file, but I was unable to come up with a way to do this. The following is *kinda* what I want, but it's wrong:

RewriteRule ^/$ controller/action [QSA]

I don't understand this syntax well enough.

The other thing that I tried was to play with the routes:

map.connect '', :controller => 'controller', :action => 'my_action'

and then do a Rails 'redirect_to' in the "my_action" method of the controller. This doesn't work as well.

Any ideas on how to do this?

Appreciated.

parki...




Re: Help getting top level redirect set up with Ra

Posted by: kchrist
Posted on: 2006-06-23 09:54:00

Rails redirections are done internally, so you don't need to put anything in .htaccess. You just set up the route you want in config/routes.rb. Using redirect_to is not necessary.

See the Rails routing docs for details.

Tags: mydomainredirectactionhtaccess fileqsahttpsyntaxconsistentsurfpathideaaccessmaphelp