Skip to content

Commit

Permalink
Force SSL on a page if system.force_ssl is enabled (#899)
Browse files Browse the repository at this point in the history
* Force SSL on a page if system.force_ssl is enabled

* Blueprint for force_ssl option

* Add default false for force_ssl
  • Loading branch information
flaviocopes authored Jul 20, 2016
1 parent 9b67359 commit 98534bc
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
13 changes: 12 additions & 1 deletion system/blueprints/config/system.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -513,7 +513,7 @@ form:
label: PLUGIN_ADMIN.MEMCACHED_PORT
help: PLUGIN_ADMIN.MEMCACHED_PORT_HELP
placeholder: "11211"

cache.redis.server:
type: text
size: medium
Expand Down Expand Up @@ -1018,3 +1018,14 @@ form:
options:
':': ': (default)'
';': '; (for Apache running on Windows)'

force_ssl:
type: toggle
label: PLUGIN_ADMIN.FORCE_SSL
highlight: 0
help: PLUGIN_ADMIN.FORCE_SSL_HELP
options:
1: PLUGIN_ADMIN.YES
0: PLUGIN_ADMIN.NO
validate:
type: bool
2 changes: 1 addition & 1 deletion system/config/system.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ default_locale: # Default locale (defaults to system
param_sep: ':' # Parameter separator, use ';' for Apache on windows
wrapped_site: false # For themes/plugins to know if Grav is wrapped by another platform
reverse_proxy_setup: false # Running in a reverse proxy scenario with different webserver ports than proxy

force_ssl: false # If enabled, Grav forces to be accessed via HTTPS

languages:
supported: [] # List of languages supported. eg: [en, fr, de]
Expand Down
6 changes: 6 additions & 0 deletions system/src/Grav/Common/Service/PageServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@ public function register(Container $container) {

// Redirection tests
if ($page) {
if ($c['config']->get('system.force_ssl')) {
if (!isset($_SERVER['HTTPS']) || $_SERVER["HTTPS"] != "on") {
$url = "https://" . $_SERVER["HTTP_HOST"] . $_SERVER["REQUEST_URI"];
$c->redirect($url);
}
}

$url = $page->route();

Expand Down

0 comments on commit 98534bc

Please sign in to comment.