Skip to content

Instantly share code, notes, and snippets.

@joshuabaker
Created July 14, 2015 18:44
Show Gist options
  • Star 6 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save joshuabaker/bb45340bc4eda4c7d932 to your computer and use it in GitHub Desktop.
Save joshuabaker/bb45340bc4eda4c7d932 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