简体   繁体   中英

Double slashes in URL and rails route system

In my Rails application two URL such as

http://myurl/foo/bar
http://myurl/foo//bar

Are processed the same way. It's pretty smart from Rails to ignore the empty attributes contained between slashes but it becomes a problem when I link everything with the front-end Javascript framework ; my front-end routing system blows up because of it.

In my opinion, this should be understood as a problem in the URL by Rails because it seems more strict and logical.

Therefore, I would like to simply redirect the user to the homepage when the routes.rb detects a // within the path ; how is this possible ?

Thank you ;)

EDIT :

I tried this kind of things

match ':url' => redirect('/'), :constraints => { url: /\/+/ }, via: [:get, :post]

And it doesn't work, seems like the route file is read after rails manipulate the absolute URL first, or something like that ...

I would try writing a regular expression the validates the route before it is passed to the specific controller to process the route. If the validation proves that the url is invalid it redirects to the home route

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM