문제

Is it possible to combine these in to one statement?

  match '/:action', to: redirect('/'), constraints: {action: /properties/}, via: :all
  match '/:action/*other', to: redirect('/'), constraints: {action: /properties/}, via: :all

I want to redirect to the root url if the root url the user has entered starts with /properties (e.g. www.google.com/properties, www.google.com/properties/foo/bar, www.google.com/properties/1/bar/foo/baz/test). All those examples should go back to www.google.com.

EDIT

I ended up with match '/:action(/*anything)', to: redirect('/'), constraints: {action: /properties/}, via: :all

도움이 되었습니까?

해결책

Make them optional.

match '/:action(/:other)', to: redirect('/'), constraints: {action: /properties/, other: [a-zA-Z0-9\/\\]+ }, via: :all

From the doc:

get ':controller(/:action(/:id))'

This route will also route the incoming request of /photos to PhotosController#index, since :action and :id are optional parameters, denoted by parentheses.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top