There is an option in ActionDispatch called trailing_slash
you can use to force the trailing slash at the end of the URL. I'm not sure if it can be used in the routing definition.
def tes_trailing_slsh
add_host!
options = {:controller => 'foo', :trailing_slash => true, :action => 'bar', :id => '33'}
assert_equal('http://www.basecamphq.com/foo/bar/33/', W.new.url_for(options) )
end
In your case, the best way is to use Rack or your web server to execute the redirect.
In Apache, you can add a definition such as
RewriteEngine on
RewriteRule ^(.+[^/])$ $1/ [R=301,L]
To redirect all routes without a trailing slash to the corresponding one with trailing slash.
Or you can use rack-rewrite to perform the same task in your Rails app at Rack level.
original_url
also includes query parameters, so this check catches too much. – Kobi