{"id":8126,"date":"2015-11-27T03:33:47","date_gmt":"2015-11-27T03:33:47","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2015\/11\/27\/laravel-redirect-all-requests-to-https-open-source-projects-laravel-laravel\/"},"modified":"2022-08-30T15:45:32","modified_gmt":"2022-08-30T15:45:32","slug":"laravel-redirect-all-requests-to-https-open-source-projects-laravel-laravel","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2015\/11\/27\/laravel-redirect-all-requests-to-https-open-source-projects-laravel-laravel\/","title":{"rendered":"Laravel Redirect All Requests To HTTPS-open source projects laravel\/laravel"},"content":{"rendered":"<p><img decoding=\"async\" src=\"http:\/\/i.stack.imgur.com\/t8POr.jpg?s=128&amp;g=1\" \/> <strong>Pedro Henrique A. Oliveira<\/strong><\/p>\n<p>I don&#8217;t understand about HTTP and HTTPS in detail, so I&#8217;m sorry if this answer isn&#8217;t very good.<\/p>\n<p>It&#8217;s my understanding that there is an issue that even when client and (client specified) server are using HTTPS, <code>Request::secure()<\/code> can return false because your application may be running on a different server, which is possibly not receiving a https request.<\/p>\n<p>I&#8217;m hosting my laravel app in heroku and it seems it does that. My <b><i>guess<\/i><\/b> is that the primary (client specified) server is a load balancer and when the request is forwarded, it arrives at the other server as a normal HTTP request.<\/p>\n<p>When such forwarding can happen, you should not just check for <code>Request::secure()<\/code> to be <code>true<\/code>. I was instructed (by someone in #laravel @ irc.freenode.com) to also check <code>Request::server('HTTP_X_FORWARDED_PROTO')<\/code> to see if it&#8217;s equal to <code>'https'<\/code>.<\/p>\n<p>So if you intend to follow the other advice in here and perform a redirect in case of non-secure, try checking for this server parameter too.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Pedro Henrique A. Oliveira I don&#8217;t understand about HTTP and HTTPS in detail, so I&#8217;m sorry if this answer isn&#8217;t very good. It&#8217;s my understanding that there is an issue that even when client and (client specified) server are using HTTPS, Request::secure() can return false because your application may be running on a different server, [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7,1],"tags":[],"class_list":["post-8126","post","type-post","status-publish","format-standard","hentry","category-laravel","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/8126","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=8126"}],"version-history":[{"count":1,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/8126\/revisions"}],"predecessor-version":[{"id":8600,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/8126\/revisions\/8600"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=8126"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=8126"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=8126"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}