Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails 3 Routing based on regex

I want to redirect all routes that start with the string xyz to some other path.

match /\/xyz\/(.)*/ => redirect{ "whateverurl" }

The match method doesn't seem to work when given a regex, I have googled alot seems like there are options to do with regex but they are for params for example

match 'photos/:id' => 'photos#show', :constraints => { :id => /[A-Z]\d{5}/ }

How can I achieve it ?

like image 305
Abid Avatar asked Oct 11 '12 19:10

Abid


1 Answers

How about:

match '/xyz/*foo' => redirect('url')

It's not a regexp, it's called route globbing. More about it here.

like image 159
jdoe Avatar answered Sep 24 '22 12:09

jdoe