-
Notifications
You must be signed in to change notification settings - Fork 5
/
README
50 lines (30 loc) · 1.63 KB
/
README
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
RedirectRouting
===============
This plugin lets you do simple redirects straight from your routes.rb file:
map.redirect '', :controller => 'events'
This will make the root of your site redirect to the events controller, typically at /events.
You can redirect any URL to any set of options, or event a string URL, like this:
map.redirect 'test', 'http://pinds.com'
GET /test, and you'll be redirected to my blog.
You can also set the status to be a 301 permanent redirect instead of a temporary 302:
map.redirect 'oldurl', 'newurl', :permament => true
map.redirect 'oldurl', :controller => 'new_controller', :action => 'new_action', :permament => true
Motivation
----------
Why this plugin?
Because if Rails Routing is supposed to be a Ruby replacement for mod_rewrite, then at least some redirect capability is called for.
But more concretely, because there's no good alternative unless you're using Apache. The alternative options that I've been able to figure out are:
* Configure your web server to do the redirect for you, which is trivial with mod_rewrite in Apache, but not so trivial with Mongrel, or
* Manually create a controller for the sole purpose of redirecting, or
* Tack the redirect onto another controller, which isn't very RESTful
If you know of a simpler way to do this, please let me know.
Credits
-------
Written by Lars Pind
http://pinds.com
Changelog
---------
* Updated to Rails Edge [Manfred Stienstra]
* Support for 301 redirects [Gioele Barabucci]
* Silence warning about missing helper [Tim Connor]
* Gobble up options[:conditions], so it doesn't get included in the URL redirected to [guillaumegentil]