Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Added second boolean parameter to Base.redirect_to_url and Response#r…

…edirect to control whether the redirect is permanent or not (301 vs 302) #375 [Hodel]

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@293 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information...
commit 2e1a27fa4de4460808405bdb7771ae2c59b99dd1 1 parent 9a5321f
@dhh dhh authored
View
2  actionpack/CHANGELOG
@@ -1,5 +1,7 @@
*SVN*
+* Added second boolean parameter to Base.redirect_to_url and Response#redirect to control whether the redirect is permanent or not (301 vs 302) #375 [Hodel]
+
* Fixed that @request.remote_ip didn't work in the test environment #369 [Bruno Mattarollo]
* Added :host and :protocol options to url_for and friends to redirect to another host and protocol than the current.
View
7 actionpack/lib/action_controller/base.rb
@@ -529,10 +529,11 @@ def redirect_to_path(path) #:doc:
end
# Redirects the browser to the specified <tt>url</tt>. Used to redirect outside of the current application. Example:
- # <tt>redirect_to_url "http://www.rubyonrails.org"</tt>.
- def redirect_to_url(url) #:doc:
+ # <tt>redirect_to_url "http://www.rubyonrails.org"</tt>. If the resource has moved permanently, it's possible to pass true as the
+ # second parameter and the browser will get "301 Moved Permanently" instead of "302 Found".
+ def redirect_to_url(url, permanently = false) #:doc:
logger.info("Redirected to #{url}") unless logger.nil?
- @response.redirect(url)
+ @response.redirect(url, permanently)
@performed_redirect = true
end
View
4 actionpack/lib/action_controller/response.rb
@@ -7,8 +7,8 @@ def initialize
@body, @headers, @session, @assigns = "", DEFAULT_HEADERS.merge("cookie" => []), [], []
end
- def redirect(to_url)
- @headers["Status"] = "302 Moved"
+ def redirect(to_url, permanently = false)
+ @headers["Status"] = permanently ? "301 Moved Permanently" : "302 Found"
@headers["location"] = to_url
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.