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 ######
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
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)).
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.