match in rails routes.rb is redirecting too many times

谁都会走 提交于 2019-12-06 12:26:02

问题


I have a route that is suppose to match something like this
localhost:3000/site/admin

and redirect to

localhost:3000/en/site/admin

here is the route line that should match this
routes.rb

match '*path', to: redirect("/#{I18n.default_locale}/%{path}")

but instead of matching it and redirecting to localhost:3000/en/site/admin, It's redirecting infite to this

http://localhost:3000/en/en/en/en/en/en/en/en/en/en/en/en/en/site/admin
(adds /en until browser complains about infite loop)

Any idea why this infite loops is happening? Thanks

EDIT

Link to my my entire routes.rb file

https://gist.github.com/2323762


回答1:


Do you have a route higher up in the file that catches the "/:locale/:path" URL that you're redirecting to? If not, your route will fall through and be caught once again by the "*path" route (which matches anything).



来源:https://stackoverflow.com/questions/10050148/match-in-rails-routes-rb-is-redirecting-too-many-times

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!