rack-rewrite remove slashes if not pattern

£可爱£侵袭症+ 提交于 2019-12-25 01:51:39

问题


I'm using rack-rewrite in my app to remove trailing slashes if found, but I only want that if not on a certain route.

I've used something like:

use Rack::Rewrite do
  r301 %r{^(?!testroute)(.+)/$}, '$1'
end

To achieve what I need (e.g. all routes but /testroute/ should have any trailing slashes removed). The issue is that even if it hits that specific route, it does not ignore it and it remove the trailing slashes. Is my regex wrong, or is there something that I am not considering?


回答1:


Try using this instead.

r301 %r{^(?!.*testroute)(.+)/$}, '$1'


来源:https://stackoverflow.com/questions/23324996/rack-rewrite-remove-slashes-if-not-pattern

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