Skip to content
This repository

Handler 301

Handler 301 is a plugin for Ruby on Rails that lets you easily manage 301 redirections trough a config file.

  • Change your url scheme without losing your page rank.
  • Import old url from an anterior website version easily.
  • Use named_routes for doing 301 redirection (Conserve GET parameters)

Example and usage

First, create the config/handler301.yml file and place urls you want to redirect in it :

"old_url.html": home_path
"old_url_without_path.html": home
"product_number_one.html": products_path :id => 1

Then, configure a controller that match non matching routes in your config/routes.rb

Rails2

ActionController::Routing::Routes.draw  do |map|
  map.connect "*path", :controller => 'error', :action => 'handle404'
end

Rails3

MkdBaseApp::Application.routes.draw do
  match "*path" => 'error#handle404'
end

And finally, in your ErrorController (or whatever the name of your non matching routes controller) :

class ErrorController < ApplicationController
  def handle404
    unless handle_301(request.path, request.query_parameters)

      # Do your stuff here

    end
  end
end
Something went wrong with that request. Please try again.