Well, I've been hitting my head against a brick wall with this one - any help much appreciated!
I'm redirecting old urls and for the most part that's easy and working well, e.g.:
match '/pages/holiday-specials/', :to => redirect( "/accommodation", :status => 301 )
However, I need a special catch-all rule that needs to do some regex checking. This works well EXCEPT I can't get it to pass the status. This redirects and does what I need but doesn't send the 301 status:
match '/*:path', :to => redirect( lambda { |params| "/operator/#{/[^\d](\d+)([^\d]|$)/.match(params[:path])[1]}" }, :status => 301)
Any ideas?
Move the block outside the method parentheses, as follows:
match '/*:path', :to => redirect(:status => 301) { |params| "/operator/#{/[^\d](\d+)([^\d]|$)/.match(params[:path])[1]}" }
or split it over multiple lines:
match '/*:path', :to => redirect(:status => 301) do |params|
"/operator/#{/[^\d](\d+)([^\d]|$)/.match(params[:path])[1]}"
end
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With