How can you force a request in October CMS to be served over HTTPS? The usual methods used in Laravel such as adding the code below to the filters.php file don't seem to work.
Route::filter('force.ssl', function() {
if (!Request::secure()) {
return Redirect::secure(Request::getRequestUri());
}
});
If you are behind a proxy, you need something like: https://github.com/fideloper/TrustedProxy
You need to put in all your proxy IP addresses in the config for this package.
I wasn't using this so I was getting a redirect loop. After using that, all is good.
Good work that0n3guy, this does work. I made one change as shown below because I do not use CMS_ENV. I check $_SERVER['HTTP_HOST'] in bootstrap/start.php and set app()->env to either "local", "development", or "production" depending on the value.
and it fixed it on the front-end, just doesn't work for the backend. It doesn't add https:// to any of the example.com/modules/backend/ CSS or JS - If I read what you said correctly, this would work for the backend as well, but it doesn't seem to be?
Good work that0n3guy, this does work. I made one change as shown below because I do not use CMS_ENV. I check $_SERVER['HTTP_HOST'] in bootstrap/start.php and set app()->env to either "local", "development", or "production" depending on the value.
Much easier solution (well I guess this is arguable depending on your setup). Check out LetsEncrypt to get free SSL certificates for your site. That of course fixes the whole forcing SSL issue because you can just have a genuine certificate for free. If you're using something like Laravel Forge to host the site, simply go to the site, click "SSL Certificates", click "LetsEncrypt (Beta)", and then "Obtain Certificate". In a matter of a minute you have a free genuine cert.
There's only one catch (well kinda), and that's:
LetsEncrypt certificates expire after 90 days; however, you may easily auto-renew them using Scheduled jobs in Forge. To get started, add the following command as a monthly scheduled job from your Forge server's management console's "Scheduler" tab
So that being said, if you're using something like forge, crazy easy to set up. Unsure of how tough it'd be otherwise.
I literally have all of my testing sub domains and such set up with it, even when throwing up a quick site. Very quick and easy to do.
Better option now available by just using CloudFlare. They have recently introduced Origin Certificates for free. It is a 15 year certificate - LetsEncrypt is great, but it is still beta and I had some bad experiences where the server didn't automatically renew the cert after 90 days (you have to renew the cert every 3 months) and my client servers went down without notice.
Highly recommend if you are already using CloudFlare, just use their free Origin Certs and problem solved. Takes 2 minutes to implement (: