Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails 301 Redirection

Tags:

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?

like image 971
Dru Avatar asked Apr 07 '12 15:04

Dru


People also ask

How do I redirect 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.

What does redirect_to return?

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.


1 Answers

Using 301 redirect in Rails

class RedirectController < ApplicationController   def index     redirect_to :root, :status => :moved_permanently   end end 
like image 103
Pavel Kalashnikov Avatar answered Sep 19 '22 13:09

Pavel Kalashnikov