redirection rule 301 on routes.rb

hi, i have created a redirection controller for redirect old pages of another previous site:

####### start code ###### class RedirectController < ApplicationController   def index     headers["Status"] = "301 Moved Permanently"     if params[:url]       redirect_to params[:url]       return     else       redirect_to index_path     end   end end ####### end code ######

in the routes.rb i have setting this rules:

####### start code ###### map.connect '/index.htm', :controller => 'redirect' map.connect '/modules.php?name=News&file=pdf&sid=87', :controller => 'redirect' ####### end code ######

for the first rule (index.htm) the redirection woks fine, but on second rule the redirection don't success. what if the correct syntax i doing to use for my purpose? thanks

map.connect ‘/modules.php?name=News&file=pdf&sid=87’, :controller =>

‘redirect’

for the first rule (index.htm) the redirection woks fine, but on second

rule the redirection don’t success.

what if the correct syntax i doing to use for my purpose?

map.connect ‘/modules.php’, :controller => ‘redirect’

The ? params are automatically extracted from the URL to the params hash in Rails, leaving the URL being the part before the ?.

If you want to redirect only specific parameters on that URL, you’ll have to handle that within your RedirectController (or alternatively handle this with a Rails metal that internally rewrites the URL and returns a 404 (to bounce it up in to Rails)).

Cheers,

Andy

thank you Andy

i have tryed with : map.connect '/modules.php', :controller => 'redirect'

but it not wook

i have try with metal too:

####### start code ###### require(File.dirname(__FILE__) + "/../../config/environment") unless defined?(Rails)

class RedirectOldSite   def self.call(env)   if env["PATH_INFO"] =~ /^\/modules\.php\?name=News&file=pdf&sid=(\d*)/       [200, {"Content-Type" => "text/html"}, ["Hello, World!"]]     else       [404, {"Content-Type" => "text/html"}, ["Not Found"]]     end   end end ####### end code ######

but it not work too.

i suppose the problem is the .php extension, because if i use the rule: /^\/modules/ and in the browser i point to mydomain/modules the rule setting in metal works fine.

any idea?

if env[“PATH_INFO”] =~ /^/modules.php?name=News&file=pdf&sid=(\d*)/

PATH_INFO already has the query string stripped off. This works for me in a quick Rails Metal:

if env[“REQUEST_URI”] =~ /^/test.php?foo=bar/

[200, {“Content-Type” => “text/html”}, [“Hello, World!”]]

else

[404, {“Content-Type” => “text/html”}, [“Not Found”]]

end

Cheers,

Andy

i have try this solution, but still don't work