Answers.Body: <p>Sound like you've accidentally <a href="https://en.wikipedia.org/wiki/Cache_poisoning" rel="nofollow noreferrer">cache-poisoned</a> yourself. A better solution than having a list of exclusions, in my opinion, is to only allow Craft to use a defined domain name. In modern versions of Craft you do this by explicitly defining the <code>@web</code> alias in your config. It's been a long time since I've used Craft 2 but I think you should be able to do the same thing using the <code>siteUrl</code> config setting (long since deprecated), and setting it explicitly to a given domain name - do not set it dynamically to &quot;whatever the current hostname&quot; is. That way, any invalid domain names or IP addresses will rightly result in an error response (which in turn should not get cached, depending on your caching strategy/technology).</p>
  <p><a href="https://craftcms.com/docs/2.x/config-settings.html#siteurl" rel="nofollow noreferrer">https://craftcms.com/docs/2.x/config-settings.html#siteurl</a></p>
  <p><a href="https://craftcms.stackexchange.com/questions/920/what-s-the-recommended-way-to-set-the-site-url/921#921">What’s the recommended way to set the site URL?</a></p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2024-10-03T17:12:02.470Z
Answers.Text: I've updated my question to include the code for my general.php config file.  
  Should the second line `define('SITE_URL',    URI_SCHEME . $_SERVER['SERVER_NAME'] . '/');`
  be altered?
Answers.UserDisplayName: buck1112
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2024-10-04T07:14:09.830Z
Answers.Text: Yep, that's what I'm saying. With that line, you're effectively saying that _any_ hostname is a valid one. Use the `siteUrl` config key inside your config array instead so that you can have different siteUrls for each environment, and change each one to be static.
Answers.UserDisplayName: James Smith
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2024-10-04T20:52:01.050Z
Answers.Text: So, is it preferable for the static hostname to be https, or is that dependent upon site setup?
Answers.UserDisplayName: buck1112
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2024-10-07T15:21:20.297Z
Answers.Text: If I have only one environment, would the static url be something like `'siteUrl' => 'https://mySite.Sites.com'`   ?
  Or, would I need to have both, an http and https version?
Answers.UserDisplayName: buck1112
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2024-10-08T08:06:58.167Z
Answers.Text: Use whatever your canonical site URL is. You can only have one per environment, naturally.
Answers.UserDisplayName: James Smith
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2024-10-03T08:10:06.897Z
Answers.LastActivityDate: 2024-10-03T08:10:06.897Z
Answers.UserDisplayName: James Smith
Body: <p>I am working with a legacy website that uses Craft 2, which will be updated in a few months.  Until then, I am wondering if there is a way to cache &quot;with exceptions&quot;?<br />
  Specifically, there has been an occurrence of a different ip address being cached (it's the ip address of another site on the same web server - all go through the same load balancer).  The hosting service claim that the load balancer could not have caused this issue.
  Is there a way to exclude all other URLs, other than the web site's URL from certain caching sections?
  Thanks for your help in this.</p>
  <p>Update:
  Here is the code for my general.php config file:</p>
  <pre><code>&lt;?php
  define('URI_SCHEME',  ( isset($_SERVER['HTTPS'] ) ) ? &quot;https://&quot; : &quot;http://&quot; );
    define('SITE_URL',    URI_SCHEME . $_SERVER['SERVER_NAME'] . '/');
    define('BASEPATH',       realpath(CRAFT_BASE_PATH . '/../') . '/');
  
   return array(
  
    '*' =&gt; array(
          'environmentVariables' =&gt; array(
          'omitScriptNameInUrls' =&gt; true,
          'siteUrl'  =&gt; SITE_URL,
          'basePath' =&gt; BASEPATH,
          'maxUploadFileSize' =&gt; 62914560,
          //path to login template - added nov6_2017
          'loginPath' =&gt; 'login',
          ),
      'devMode' =&gt; false,    
    ),
    'dev' =&gt; array(
      'devMode' =&gt; false,
    )
   );
  </code></pre>
  
Tags: <cache><craft2>
Title: How To Exclude URL or IP From Cache in Craft
ThreadText: # How To Exclude URL or IP From Cache in Craft
  
  (Asked by: username_0 on 2024-10-02)
  
  I am working with a legacy website that uses Craft 2, which will be updated in a few months. Until then, I am wondering if there is a way to cache "with exceptions"?  
  Specifically, there has been an occurrence of a different ip address being cached (it's the ip address of another site on the same web server - all go through the same load balancer). The hosting service claim that the load balancer could not have caused this issue.
  Is there a way to exclude all other URLs, other than the web site's URL from certain caching sections?
  Thanks for your help in this.
  
  Update:
  Here is the code for my general.php config file:
  
  ```
  <?php
  define('URI_SCHEME',  ( isset($_SERVER['HTTPS'] ) ) ? "https://" : "http://" );
    define('SITE_URL',    URI_SCHEME . $_SERVER['SERVER_NAME'] . '/');
    define('BASEPATH',       realpath(CRAFT_BASE_PATH . '/../') . '/');
  
   return array(
  
    '*' => array(
          'environmentVariables' => array(
          'omitScriptNameInUrls' => true,
          'siteUrl'  => SITE_URL,
          'basePath' => BASEPATH,
          'maxUploadFileSize' => 62914560,
          //path to login template - added nov6_2017
          'loginPath' => 'login',
          ),
      'devMode' => false,    
    ),
    'dev' => array(
      'devMode' => false,
    )
   );
  
  ```
  
  **Tags:** cache, craft2
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2024-10-03. Score: 2
  
  Sound like you've accidentally [cache-poisoned](https://en.wikipedia.org/wiki/Cache_poisoning) yourself. A better solution than having a list of exclusions, in my opinion, is to only allow Craft to use a defined domain name. In modern versions of Craft you do this by explicitly defining the `@web` alias in your config. It's been a long time since I've used Craft 2 but I think you should be able to do the same thing using the `siteUrl` config setting (long since deprecated), and setting it explicitly to a given domain name - do not set it dynamically to "whatever the current hostname" is. That way, any invalid domain names or IP addresses will rightly result in an error response (which in turn should not get cached, depending on your caching strategy/technology).
  
  <https://craftcms.com/docs/2.x/config-settings.html#siteurl>
  
  [What’s the recommended way to set the site URL?](https://craftcms.stackexchange.com/questions/920/what-s-the-recommended-way-to-set-the-site-url/921#921)
  
  > **Comments:**
  > **username_0**: I've updated my question to include the code for my general.php config file.   Should the second line `define('SITE_URL',    URI_SCHEME . $_SERVER['SERVER_NAME'] . '/');` be altered?  
  > **username_1**: Yep, that's what I'm saying. With that line, you're effectively saying that _any_ hostname is a valid one. Use the `siteUrl` config key inside your config array instead so that you can have different siteUrls for each environment, and change each one to be static.  
  > **username_0**: So, is it preferable for the static hostname to be https, or is that dependent upon site setup?  
  > **username_0**: If I have only one environment, would the static url be something like `'siteUrl' => 'https://mySite.Sites.com'`   ? Or, would I need to have both, an http and https version?  
  > **username_1**: Use whatever your canonical site URL is. You can only have one per environment, naturally.  
  
  ---
  
  