Rails: Mapping root_url to an external url

女生的网名这么多〃 提交于 2019-12-20 04:46:41

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!