Is it possible to redirect a url that uses HTTPS p

2019-09-10 01:39发布

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.

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.

UPDATE:

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

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."

2条回答
我只想做你的唯一
2楼-- · 2019-09-10 02:22

For your site to even respond on https://myolddomain.com it will need to have the certificate for myolddomain.com else it will fail with a certificate mismatch as Heroku have a wildcard cert *.herokuapp.com by default on all apps - the certificate will be checked before any rack modules are executed.

If you want to handle the https traffic at Heroku your only option will be to buy a an SSL and use the SSL endpoint addon.

Or, you could use an external server to redirect the old domain (with the certificate for the loaded) to redirect to the new domain on Heroku.

查看更多
乱世女痞
3楼-- · 2019-09-10 02:34

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.

You could write your custom rules in a .htaccess file in the root of your application

See links below for more info.

How do I get mod_rewrite working on Heroku?

http://wiki.nginx.org/HttpRewriteModule

http://httpd.apache.org/docs/current/mod/mod_rewrite.html

查看更多
登录 后发表回答