Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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