Help getting top level redirect set up with Rails

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…

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.


If you want useful replies, ask smart questions.