redirect to 'www' before force_ssl

前端 未结 3 1111
孤独总比滥情好
孤独总比滥情好 2021-02-10 19:14

I\'m moving an app to heroku and am having some issues with ssl and redirects.

I\'m on rails 3.1 and I\'ve tried forcing ssl with middleware in the environments producti

3条回答
  •  孤街浪徒
    2021-02-10 19:52

    Since your 301 is being sent by the application, and the request can't even reach the application before hitting the middleware (on which rack-ssl runs), your only solutions are to change the middleware or to do the redirect before it even hits the middleware.

    For the latter, you'd have to poke around Heroku. I don't use it myself. On a VPS deployment, you'd just add the redirect on your forward-facing web server (Apache, nginx) before it even hit the middleware. This seems like a common case, so I imagine Heroku might have something there for you.

    For the former, it shouldn't be hard. The rack-ssl middleware is very, very simple, and it shouldn't be hard to monkeypatch it to suit your needs.

    https://github.com/josh/rack-ssl/blob/master/lib/rack/ssl.rb#L58

    I imagine that something like url.host = "www.myhost.com" might be what you'd want (although you can probably tell there are probably more FQDN-agnostic ways to do it).

提交回复
热议问题