Redirecting subdomain to folder in Rails 3

2019-08-06 12:05发布

问题:

I need to redirect help.mydomain.com/a-page to /pages/a-page without using Nginx or Apache redirects and only through Rails 3 routes.

The key here is the help subdomain determining that /pages/ should be dropped from the route although the view is under the /views/pages/

Any help is appreciated.

回答1:

Try this:

match "/:page_name" => redirect("/pages/%{page_name}"), :constraints => { :subdomain => /help/ }