问题
We're using an external CMS to manage our site and I'd like to ensure that inside of our Rails app, root_url points out to that external url. Is there any way we can do this?
Something like:
root :to => "http://wwww.example.com"
回答1:
You can match the root of your application like this to redirect to an external URL
#
# config/routes.rb
#
root :to => redirect("http://www.google.com/")
回答2:
As @Digi_Cazter answered correctly you can do this by adding this
root :to => redirect("http://www.google.com/")
I would like to use such redirects from app only if I want specific url's to be redirected.
I would suggest you to redirect the request directly form the webserver you are using may be apache-httpd or nginx or whichever you may be using instead of passing it to app and then redirecting it.
来源:https://stackoverflow.com/questions/12079516/rails-mapping-root-url-to-an-external-url