Skip to content

Instantly share code, notes, and snippets.

@colinwilson
Forked from joshuabaker/general.php
Created March 6, 2017 00:51
Show Gist options
  • Save colinwilson/6a7bb79091e08c8937fa804fac42ec75 to your computer and use it in GitHub Desktop.
Save colinwilson/6a7bb79091e08c8937fa804fac42ec75 to your computer and use it in GitHub Desktop.
CloudFlare compatible config for Craft CMS.
<?php
if (isset($_SERVER['HTTPS']) && (strcasecmp($_SERVER['HTTPS'],'on') === 0 || $_SERVER['HTTPS'] == 1))
{
$protocol = 'https://';
}
else if ( ! empty($_SERVER['HTTP_X_FORWARDED_PROTO']))
{
$protocol = $_SERVER['HTTP_X_FORWARDED_PROTO'] . '://';
}
else if (isset($_SERVER['HTTP_CF_VISITOR']))
{
$cloudFlareVisitor = json_decode($_SERVER['HTTP_CF_VISITOR']);
if ($cloudFlareVisitor->scheme == 'https')
{
$protocol = 'https://';
}
}
else
{
$protocol = 'http://';
}
$siteUrl = $protocol . $_SERVER['HTTP_HOST'];
$fileSystemPath = realpath('..');
return array(
'*' => array(
'omitScriptNameInUrls' => true,
'siteUrl' => $siteUrl,
'baseCpUrl' => $siteUrl,
'environmentVariables' => array(
'siteUrl' => $siteUrl,
'fileSystemPath' => $fileSystemPath,
),
),
'.dev' => array(
'devMode' => true,
),
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment