1

Somehow Google indexed my homepage as https://mydomain.com. When you do a site:mydomain.com search, the first result is https://mydomain.com and I don't have a SSL cert and don't want to do https. Now our visitors get the ugly warnings in their browsers, of course (because heroku serves their *.heroku cert by default).

It seems that I can do a 301 redirect with the rack-rewrite gem but I just can't find how.

So, what is a rack-rewrite recipe to redirect all https:// to http:// ? All I can find is information on how to do the reverse thing or to make the canonical redirections.

tmaier
  • 953
  • 9
  • 17
pentor
  • 11
  • 2
  • I am trying to accomplish the exact same thing. What solution did you eventually use? – Lee Jan 05 '13 at 22:30

3 Answers3

1

Hmm, untested, but would something like this work?

r301 %r{.*}, 'http://non-secure-domain.com$&', :if => Proc.new {|rack_env|
  rack_env['SERVER_PORT'] != '80'
}
jordelver
  • 8,292
  • 2
  • 32
  • 40
0

The documentation of rack-rewrite mentions a nice way at https://github.com/jtrupiano/rack-rewrite#scheme

# Redirect all https traffic to http
r301 %r{.*}, 'http://www.example.tld$&', :scheme => 'https'
tmaier
  • 953
  • 9
  • 17
0

Using the scheme option from rack-rewrite will only cause an infinite loop on heroku. You also can't on the port being 80 because of the way heroku will proxy to your workers. Because of this and way the routing layer works, you have to check the HTTP_X_FORWARDED_PROTO header:

r301 %r{.*}, 'http://example.com$&', :if => Proc.new { |rack_env|
  rack_env['HTTP_X_FORWARDED_PROTO'] == 'https'
}
Lukas Eklund
  • 6,068
  • 1
  • 32
  • 33