Problem with Site Running Both HTTP & HTTPs So we're trying to set-up a site to run both HTTP &amp; HTTPs version in parallel for SEO auditing before making the full switch to HTTPs. We followed Ben's answer on this SE question to make it work: https://craftcms.stackexchange.com/a/4734/57.

The behavior we're seeing after implementing Ben's recommendation are that we can access both the http and https version of each page but a click on any link in the site populated by Craft templates (nav, blog overview page linking to other entries, etc.) takes us to the HTTP version of the page. So for example, if you're on https://example.com, a click on a nav link takes you to http://example.com/click rather than https://example.com/click. However, if we have a root relative link that was added manually through the control panel, that takes you to a version of the page consistent with the protocol of the current page. Basically, Craft is treating all links as if they're HTTP, even if you're on the secure version of the site. 

We would like the site to function where if you're on the HTTPs version, a click on any link keeps you on the HTTPs version. Same goes for if you're on the HTTP version, any link click takes you to another HTTP page.

Is there a way to configure Craft to make that happen?

Here are the contents of our craft/config/general.php file: 

&lt;?php

/**
 * General Configuration
 *
 * All of your system's general configuration settings go in here.
 * You can see a list of the default settings in craft/app/etc/config/defaults/general.php
 */

// SEE http://buildwithcraft.com/docs/multi-environment-configs for info


// Ensure our urls have the right scheme
define('URI_SCHEME',  ( isset($_SERVER['HTTPS'] ) &amp;&amp; $_SERVER['HTTPS'] == "on" ) ? "https://" : "http://" );

// The site url
define('SITE_URL',    URI_SCHEME . $_SERVER['SERVER_NAME'] . '/');

// The site basepath
define('BASEPATH',    realpath(CRAFT_BASE_PATH . '/../') . '/');

return array(

  // DEFAULT
  '*' =&gt; array(
    //'isSystemOn' =&gt; false,
    'omitScriptNameInUrls' =&gt; true,
    'cpTrigger' =&gt; 'discover',
    'addTrailingSlashesToUrls' =&gt; true,
    'siteUrl' =&gt; SITE_URL,
    //'devMode' =&gt; (preg_match('/dev|xip|staging/', $_SERVER['HTTP_HOST']) ? true : false),
    'devMode' =&gt; false,
    'pardotUserName' =&gt; "FILLER TEXT",
    'pardotPassword' =&gt; "FILLER TEXT",
    'pardotUserKey' =&gt; "FILLER TEXT",
    //'backupDbOnUpdate' =&gt; false,
    'generateTransformsBeforePageLoad' =&gt; true,
    // 'cacheDuration' =&gt; false,
    'defaultImageQuality' =&gt; 90,
    'caseListPagination' =&gt; 6,
  ),
  // Example dev
  'example.dev' =&gt; array(
    'devMode' =&gt; true,
    'caseListPagination' =&gt; 2,
  ),

  'example.svn.dev' =&gt; array(
    'devMode' =&gt; true
  ),

  'local.example.com' =&gt; array(
    'devMode' =&gt; true,
    // 'enableTemplateCaching' =&gt; false // Only work on Craft 2.4 and later
  ),
  'environmentVariables' =&gt; array(
    'siteUrl' =&gt; SITE_URL,
    'basePath' =&gt; BASEPATH
  ),
);


Thanks!
What web server are you running? I ask because IIS will define the $_SERVER['https'] variable even if the site is being accessed via HTTP (it's value will be 'off') and Ben's answer is only checking if the $_SERVER['https'] variable is present.

One solution is to add a further check that $_SERVER['https'] == 'on'

Try updating this:

// Ensure our urls have the right scheme
define('URI_SCHEME',  ( isset($_SERVER['HTTPS'] ) ) ? "https://" : "http://" );


to this:

// Ensure our urls have the right scheme
define('URI_SCHEME',  ( isset($_SERVER['HTTPS'] ) &amp;&amp; $_SERVER['HTTPS'] == "on" ) ? "https://" : "http://" );