Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

redirect_routing

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

redirect_routing

  • 0.0.4
  • Rubygems
  • Socket score

Version published
Maintainers
1
Created
Source

RedirectRouting

Forked by Seamus Abshere (seamus@abshere.net)

Note: you may have to put

ActionController::Routing::RouteSet::Mapper.send :include, RedirectRouting::Routes

at the top of config/routes.rb.

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://example.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

Finally you can preserve wildcard paths

map.redirect 'festivals/*path', 'http://example.com/events/festivals', :keep_path => :path
map.redirect 'news/*articles', 'http://blog.example.com', :keep_path => :articles

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 there's demand, I'll add a switch for a permanent redirect, but I don't have the need yet.

If you know of a simpler way to do this, please let me know.

Credits

Written by Lars Pind

http://pinds.com

Changelog

  • Added :keep_path options [Seamus Abshere & Manfred Stienstra]
  • Updated to Rails Edge [Manfred Stienstra]
  • Support for 301 redirects [Gioele Barabucci]
  • Silence warning about missing helper [Tim Connor]

FAQs

Package last updated on 08 Oct 2009

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc