Created
November 3, 2009 21:06
-
-
Save palexander/225437 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# The redirect controller allows for routes-based redirects | |
# as we move old content to new URL locations. | |
class RedirectController < ApplicationController | |
def index | |
if params[:url] # We were provided with a url to redirect to | |
params_string = "" | |
# Trigger to switch the placeholders | |
first_param = true | |
# Loop through the given params, ignore ones we know about or are provided by default | |
params.each do |param, value| | |
if !param.eql?("url") && !param.eql?("action") && !param.eql?("controller") | |
seperator = first_param ? "?" : "&" | |
first_param = false | |
params_string += seperator + param + "=" + value | |
end | |
end | |
# Redirect with params intact | |
redirect_to params[:url] + params_string, :status=>:moved_permanently | |
return | |
else # Default redirect to the home page | |
redirect_to "/", :status=>:moved_permanently | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment