Not found when url ends with slash

Hi everyone

I have the route:

get "/links", to: "links.index", as: :public_links_path

When I enter the url:

/links

it works

but when I enter

/links/

it doesn’t work

May be some middleware can fix it or option?

I see only one solution: using rack-rewrite

Hi @vladimirtcats, that’s right, by default we only respond to requests without trailing slashes.

I’d agree that you’d want to turn to a middleware to strip trailing slashes and return a permanent redirect to the proper URL. rack-rewrite would do the job well.

Here’s a snippet from @parndt in response to an earlier discussion on GitHub:

# config.ru

require "rack/rewrite"

use Rack::Rewrite do
  # remove trailing slashes
  r302 %r{(/.*)/(\?.*)?$}, "$1$2"
end
1 Like