Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Force SSL on a page if system.force_ssl is enabled #899

Merged
merged 4 commits into from
Jul 20, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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