是否可以重定向使用HTTPS协议的网址? (Heroku,Rails) [英] Is it possible to redirect a url that uses HTTPS protocol? (Heroku, Rails)
问题描述
我切换了我的应用程式的网域,重新导向适用于使用http的网址,但是我在网路上隐藏了一些链接,而这些链接并未重新导向。
I switched my app's domain, and the redirect works for urls that use http, but I have some links lurking around on the web using HTTPS that aren't redirecting.
例如, http://myolddomain.com 仅重定向很好,但 https://myolddomain.com 结果只返回一般的服务器错误。是否可以重定向这些链接?我正在使用rails 3和heroku。
For instance, http://myolddomain.com redirects just fine, but https://myolddomain.com results just returns a generic server error. Is it possible to redirect these links? I'm using rails 3 and heroku.
更新:
我正在尝试机架重写宝石。以下是我要添加到我的生产环境文件中的代码:
I'm trying the rack-rewrite gem. Here's the code that I'm adding to my production environment file:
#mod_rewrite using rack-rewrite gem
config.middleware.insert_before(Rack::Lock, Rack::Rewrite) do
rewrite '^https://www.myolddomain.com/(.*)$', 'https://www.mynewdomain.com/$1'
rewrite '^https://myolddomain.com/(.*)$', 'https://www.mynewdomain.com/$1'
end
它已成功重定向 https:// myolddomain。 com ,而不是 https://www.myoldomain.com 。它也为ssl证书发出错误,服务器的证书与URL不匹配。
It's successfully redirecting https://myolddomain.com but not https://www.myoldomain.com. It's also throwing an error for the ssl certificate, "Server's certificate does not match the URL."
推荐答案
您可以使用apache或nginx来实现这一点。他们都支持url重定向。您只需要指定两个规则,一个用于http,另一个用于https。虽然,Im积极,你可以写一个正则表达式来包括两者。
One way you can do it is with apache or nginx. They both support url redirect. You would just need to specify two rules, one for http and another one for https. Although, Im positive you could just write a regex to include both.
你可以在应用程序的根目录中的.htaccess文件中编写你的自定义规则
You could write your custom rules in a .htaccess file in the root of your application
查看以下链接了解更多信息。
See links below for more info.
http://wiki.nginx.org/HttpRewriteModule
http://httpd.apache.org/docs/current/mod/mod_rewrite .html
这篇关于是否可以重定向使用HTTPS协议的网址? (Heroku,Rails)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!