Rails 4 通配符重定向
Rails 4 wild card redirect
我正在尝试找到一种方法来重定向 Rails 4 上 Ruby 上的路由,该路由应符合以下条件:
http://domain.com/articles/GG-*
所以在 GG-
之后每个包含各种数字的页面都应该被重定向。我目前拥有的:
get 'articles/GG-*', to: redirect("newdomain.com", status: 301), via :all
如果我只在路由文件本身上键入许多 GG-12312313
页面之一,重定向部分将起作用,但我无法创建通配符来捕获 GG-
之后的所有字符。感谢您的帮助!
您可以使用 wildcards for full segments of the route like /foo/*bar
, but to match a more specific regexp, you need to use constraints.
get 'articles/:id',
constraints: { id: /GG-.*/ },
to: redirect("https://google.com", status: 301)
我正在尝试找到一种方法来重定向 Rails 4 上 Ruby 上的路由,该路由应符合以下条件:
http://domain.com/articles/GG-*
所以在 GG-
之后每个包含各种数字的页面都应该被重定向。我目前拥有的:
get 'articles/GG-*', to: redirect("newdomain.com", status: 301), via :all
如果我只在路由文件本身上键入许多 GG-12312313
页面之一,重定向部分将起作用,但我无法创建通配符来捕获 GG-
之后的所有字符。感谢您的帮助!
您可以使用 wildcards for full segments of the route like /foo/*bar
, but to match a more specific regexp, you need to use constraints.
get 'articles/:id',
constraints: { id: /GG-.*/ },
to: redirect("https://google.com", status: 301)