src/Control/Director.php
public static function forceSSL($patterns = null, $secureDomain = null, HTTPRequest $request = null)
    {
        $handler = CanonicalURLMiddleware::singleton()->setForceSSL(true);
        if ($patterns) {
            $handler->setForceSSLPatterns($patterns);
        }
        if ($secureDomain) {
            $handler->setForceSSLDomain($secureDomain);
        }
        $handler->throwRedirectIfNeeded($request);
    }
public static function forceSSL($patterns = null, $secureDomain = null, HTTPRequest $request = null)
    {
        $handler = CanonicalURLMiddleware::singleton()->setForceSSL(true);
        if ($patterns) {
            $handler->setForceSSLPatterns($patterns);
        }
        if ($secureDomain) {
            $handler->setForceSSLDomain($secureDomain);
        }
        $handler->throwRedirectIfNeeded($request);
    }
public static function forceSSL ( $ patterns = null , $ secureDomain = null , HTTPRequest $ request = null ) { $ handler = CanonicalURLMiddleware :: singleton ( ) -> setForceSSL ( true ) ; if ( $ patterns ) { $ handler -> setForceSSLPatterns ( $ patterns ) ; } if ( $ secureDomain ) { $ handler -> setForceSSLDomain ( $ secureDomain ) ; } $ handler -> throwRedirectIfNeeded ( $ request ) ; }
Force the site to run on SSL.

To use, call from _config.php. For example:
<code>
if (Director::isLive()) Director::forceSSL();
</code>

If you don't want your entire site to be on SSL, you can pass an array of PCRE regular expression
patterns for matching relative URLs. For example:
<code>
if (Director::isLive()) Director::forceSSL(array('/^admin/', '/^Security/'));
</code>

If you want certain parts of your site protected under a different domain, you can specify
the domain as an argument:
<code>
if (Director::isLive()) Director::forceSSL(array('/^admin/', '/^Security/'), 'secure.mysite.com');
</code>

Note that the session data will be lost when moving from HTTP to HTTPS. It is your responsibility
to ensure that this won't cause usability problems.

CAUTION: This does not respect the site environment mode. You should check this
as per the above examples using Director::isLive() or Director::isTest() for example.

@param array $patterns Array of regex patterns to match URLs that should be HTTPS.
@param string $secureDomain Secure domain to redirect to. Defaults to the current domain.
Can include port number.
@param HTTPRequest|null $request Request object to check
Force the site to run on SSL .