I would like to redirect multiple entries to my landing page to one url.
The following urls, http://mysite.com
and http://www.mysite.com
, would redirect to http://www.mysite.com/
using 301 redirection. How can/should this be done in Rails?
Rails's redirect_to takes two parameters, option and response_status (optional). It redirects the browser to the target specified in options. This parameter can be: Hash - The URL will be generated by calling url_for with the options.
redirect_to will cause any automatic rendering to be skipped. You only need the 'return' if you need to bypass further code in the action. If the further code does an explicit render , then you must do a return to avoid an error of redirect and render both being present.
Using 301 redirect in Rails
class RedirectController < ApplicationController def index redirect_to :root, :status => :moved_permanently end end
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With