Вопрос

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