Answers.Body: <p>What web server are you running? I ask because IIS will define the <code>$_SERVER['https']</code> variable <a href="http://php.net/manual/en/reserved.variables.server.php" rel="nofollow noreferrer">even if the site is being accessed via HTTP</a> (it's value will be 'off') and Ben's answer is only checking if the <code>$_SERVER['https']</code> variable is present.</p>
  
  <p>One solution is to add a further check that <code>$_SERVER['https'] == 'on'</code></p>
  
  <p>Try updating this:</p>
  
  <pre><code>// Ensure our urls have the right scheme
  define('URI_SCHEME',  ( isset($_SERVER['HTTPS'] ) ) ? "https://" : "http://" );
  </code></pre>
  
  <p>to this:</p>
  
  <pre><code>// Ensure our urls have the right scheme
  define('URI_SCHEME',  ( isset($_SERVER['HTTPS'] ) &amp;&amp; $_SERVER['HTTPS'] == "on" ) ? "https://" : "http://" );
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-02-14T22:18:04.833Z
Answers.Text: Hey Tom, thanks so much for the response! I made the suggested update but am still seeing the same behavior.
  
  We're running ubuntu on Apache.
Answers.UserDisplayName: dpayne
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-02-15T02:19:50.347Z
Answers.Text: Also, note that I updated the original question from the time of your response to highlight the different between links populated from the CMS and root relatives that are manually added, just in case it changes anything.
Answers.UserDisplayName: dpayne
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-02-15T15:19:29.123Z
Answers.Text: It could be that your PHP config isn't outputting the `$_SERVER` variable, although it's unlikely. Lets start with the basics. Are you able to create a temporary file in your public directory and show the output of `<?php die(var_dump(isset($_SERVER['HTTPS'])));` for both HTTP and HTTPS. Remember to remove the file when you're done.
  
  Also, are you definitely setting the `siteUrl` config variable in config.php at the root of the array or under the '*' key?
Answers.UserDisplayName: Tom
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-02-15T18:24:18.410Z
Answers.Text: Hey Tom, when I upload the temporary file and go to the HTTPs version, I see "bool(true)." When I go to the HTTP version, I see "bool(false)."
  
  As to the siteUrl config, setting it at the root of the array, yes.
  
  Thoughts?
Answers.UserDisplayName: dpayne
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-02-15T19:45:00.973Z
Answers.Text: Can you post the contents of your ``craft/config/general.php``?  Probably overlooking something.
Answers.UserDisplayName: RitterKnight
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-02-15T19:54:07.910Z
Answers.Text: Sure thing! Original question updated above.
Answers.UserDisplayName: dpayne
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-02-16T21:12:36.627Z
Answers.Text: I don't think this will be the cause of your problem, but you probably want to move you `environmentVariables` array under the `*` as seen [here](https://craftcms.com/docs/multi-environment-configs#environment-specific-variables) in the docs. You're seeing the incorrect schema in the HTML source for links generated like this `{{ entry.url }}`? Do you have any redirects set in a .htaccess files for HTTP vs. HTTPS?
Answers.UserDisplayName: Tom
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-02-16T21:40:23.153Z
Answers.Text: Thanks, Tom. Changing environment variables didn't cause any change. Also, confirming that {{ entry.url }} is always outputting a page on http protocol, even if clicked from https. Checked .htaccess and no redirects that would push to http vs. https or vice versa. We do use a redirect plugin within Craft: https://github.com/rkingon/Craft-Plugin--Redirect-Manager but I disabled it and no change and, as far as I know, it shouldn't create an issue anyway.
Answers.UserDisplayName: dpayne
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-02-16T21:54:38.173Z
Answers.Text: No problem. It was a bit of a long shot. I span up a new Craft install, and aside from the database config, the only setting I've changed is: `'siteUrl' => (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') ? 'https://craft.dev' : 'http://craft.dev',` within [general.php](https://gist.github.com/tomwelch/88f65f66190e14647e59375145a4413c#file-general-php-L13) it's just a different method to defining the globals like you have. Give it a whirl. I'm in Craft's Slack if you want to find me there (tomw).
Answers.UserDisplayName: Tom
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-02-17T02:10:28.147Z
Answers.Text: You might try `'siteUrl' => '/',`
  That should leave all the links on the same protocol.
Answers.UserDisplayName: Marion Newlevant
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-02-17T20:29:29.587Z
Answers.Text: Oh man ok - so got the issue fixed. I thought that all {{ entry.url }} links were outputting with http protocol. However, upon further investigation, I found that many page templates actually were outputting the correct protocol on an {{entry.url }} link and it was only the nav where the issue was occurring. Turns out that was happening due to the Craft cache tag that was wrapped around the nav. Once I removed the cache tag, the nav links worked correctly. Anyway, thanks to all for the help! Will mark this answered.
Answers.UserDisplayName: dpayne
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-02-14T19:39:30.687Z
Answers.LastActivityDate: 2017-02-14T19:39:30.687Z
Answers.UserDisplayName: Tom
Body: <p>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: <a href="https://craftcms.stackexchange.com/a/4734/57">https://craftcms.stackexchange.com/a/4734/57</a>.</p>
  
  <p>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 <a href="https://example.com" rel="nofollow noreferrer">https://example.com</a>, a click on a nav link takes you to <a href="http://example.com/click" rel="nofollow noreferrer">http://example.com/click</a> rather than <a href="https://example.com/click" rel="nofollow noreferrer">https://example.com/click</a>. 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. </p>
  
  <p>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.</p>
  
  <p>Is there a way to configure Craft to make that happen?</p>
  
  <p>Here are the contents of our craft/config/general.php file: </p>
  
  <pre><code>&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
    ),
  );
  </code></pre>
  
  <p>Thanks!</p>
  
Tags: <users><url><config><siteurl><https>
Title: Problem with Site Running Both HTTP & HTTPs
ThreadText: # Problem with Site Running Both HTTP & HTTPs
  
  (Asked by: username_0 on 2017-02-14)
  
  So we're trying to set-up a site to run both HTTP & 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:
  
  ```
  <?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'] ) && $_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
    '*' => array(
      //'isSystemOn' => false,
      'omitScriptNameInUrls' => true,
      'cpTrigger' => 'discover',
      'addTrailingSlashesToUrls' => true,
      'siteUrl' => SITE_URL,
      //'devMode' => (preg_match('/dev|xip|staging/', $_SERVER['HTTP_HOST']) ? true : false),
      'devMode' => false,
      'pardotUserName' => "FILLER TEXT",
      'pardotPassword' => "FILLER TEXT",
      'pardotUserKey' => "FILLER TEXT",
      //'backupDbOnUpdate' => false,
      'generateTransformsBeforePageLoad' => true,
      // 'cacheDuration' => false,
      'defaultImageQuality' => 90,
      'caseListPagination' => 6,
    ),
    // Example dev
    'example.dev' => array(
      'devMode' => true,
      'caseListPagination' => 2,
    ),
  
    'example.svn.dev' => array(
      'devMode' => true
    ),
  
    'local.example.com' => array(
      'devMode' => true,
      // 'enableTemplateCaching' => false // Only work on Craft 2.4 and later
    ),
    'environmentVariables' => array(
      'siteUrl' => SITE_URL,
      'basePath' => BASEPATH
    ),
  );
  
  ```
  
  Thanks!
  
  **Tags:** users, url, config, siteurl, https
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2017-02-14. Score: 3 | Accepted answer
  
  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](http://php.net/manual/en/reserved.variables.server.php) (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'] ) && $_SERVER['HTTPS'] == "on" ) ? "https://" : "http://" );
  
  ```
  
  > **Comments:**
  > **username_0**: Hey Tom, thanks so much for the response! I made the suggested update but am still seeing the same behavior.  We're running ubuntu on Apache.  
  > **username_0**: Also, note that I updated the original question from the time of your response to highlight the different between links populated from the CMS and root relatives that are manually added, just in case it changes anything.  
  > **username_1**: It could be that your PHP config isn't outputting the `$_SERVER` variable, although it's unlikely. Lets start with the basics. Are you able to create a temporary file in your public directory and show the output of `<?php die(var_dump(isset($_SERVER['HTTPS'])));` for both HTTP and HTTPS. Remember to remove the file when you're done.  Also, are you definitely setting the `siteUrl` config variable in config.php at the root of the array or under the '*' key?  
  > **username_0**: Hey Tom, when I upload the temporary file and go to the HTTPs version, I see "bool(true)." When I go to the HTTP version, I see "bool(false)."  As to the siteUrl config, setting it at the root of the array, yes.  Thoughts?  
  > **username_2**: Can you post the contents of your ``craft/config/general.php``?  Probably overlooking something.  
  > **username_0**: Sure thing! Original question updated above.  
  > **username_1**: I don't think this will be the cause of your problem, but you probably want to move you `environmentVariables` array under the `*` as seen [here](https://craftcms.com/docs/multi-environment-configs#environment-specific-variables) in the docs. You're seeing the incorrect schema in the HTML source for links generated like this `{{ entry.url }}`? Do you have any redirects set in a .htaccess files for HTTP vs. HTTPS?  
  > **username_0**: Thanks, Tom. Changing environment variables didn't cause any change. Also, confirming that {{ entry.url }} is always outputting a page on http protocol, even if clicked from https. Checked .htaccess and no redirects that would push to http vs. https or vice versa. We do use a redirect plugin within Craft: https://github.com/rkingon/Craft-Plugin--Redirect-Manager but I disabled it and no change and, as far as I know, it shouldn't create an issue anyway.  
  > **username_1**: No problem. It was a bit of a long shot. I span up a new Craft install, and aside from the database config, the only setting I've changed is: `'siteUrl' => (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') ? 'https://craft.dev' : 'http://craft.dev',` within [general.php](https://gist.github.com/tomwelch/88f65f66190e14647e59375145a4413c#file-general-php-L13) it's just a different method to defining the globals like you have. Give it a whirl. I'm in Craft's Slack if you want to find me there (tomw).  
  > **username_3**: You might try `'siteUrl' => '/',` That should leave all the links on the same protocol.  
  > **username_0**: Oh man ok - so got the issue fixed. I thought that all {{ entry.url }} links were outputting with http protocol. However, upon further investigation, I found that many page templates actually were outputting the correct protocol on an {{entry.url }} link and it was only the nav where the issue was occurring. Turns out that was happening due to the Craft cache tag that was wrapped around the nav. Once I removed the cache tag, the nav links worked correctly. Anyway, thanks to all for the help! Will mark this answered.  
  
  ---
  
  