<p>I generally find this snippet to be useful</p>

<pre><code>(isset($_SERVER['HTTPS']) ? 'https://' : 'http://') . $_SERVER['SERVER_NAME']
</code></pre>

<p>Especially if you set up a virtual host locally in most situations you can define this in your * and it will work across local/staging/production.</p>

<p>Here's a basic example config:</p>

<pre><code>'*' =&gt; [
    'environmentVariables' =&gt; [
        'basePath' =&gt; '/Users/your/path/to/site/',
        'baseUrl' =&gt; (isset($_SERVER['HTTPS']) ? 'https://' : 'http://') . $_SERVER['SERVER_NAME']
    ],
    'enableCsrfProtection' =&gt; true,
    'devMode' =&gt; true,      
],

'live' =&gt; [
     'environmentVariables' =&gt; [
        'basePath' =&gt; '/srv/different/path/to/site/',
     ],
]
</code></pre>

CC BY-SA 3.0
2017-04-17T22:10:25.097Z
Would you be able to edit this answer and include a snippet of the config file including this line to help others.
JMKelley
CC BY-SA 3.0
2017-04-17T18:43:13.070Z
2017-08-15T21:51:32.353Z
2017-08-15T21:51:32.353Z
sgtpenguin
<p>Fixed by changing the following line:</p>

<pre><code>'siteUrl' =&gt; 'http://testurl.com',
</code></pre>

CC BY-SA 3.0
2017-04-17T18:30:18.040Z
2017-04-17T18:30:18.040Z
JMKelley
<p>Make sure your PRIMARY_SITE_URL in your .env file contains the url scheme.
Example :
PRIMARY_SITE_URL=http://test.localhost</p>

CC BY-SA 4.0
2021-04-18T09:23:25.397Z
2021-04-18T09:23:25.397Z
Mathias Marrillet
<p>When calling my links, they're appearing and trying to link like so:</p>

<blockquote>
  <p>testurl.com/university/testurl.com/university/arizona-state/</p>
</blockquote>

<p>Really it should just be </p>

<blockquote>
  <p>testurl.com/university/arizona-state/</p>
</blockquote>

<p>The line that is generating a category URL:</p>

<pre><code>        &lt;a class="university-widget w-inline-block" href="{{ category.url }}"&gt;
</code></pre>

<p>and my general.php:</p>

<pre><code>return array(

  '*' =&gt; array(
  ),

  'localhost' =&gt; array(
    'devMode' =&gt; true,
    'siteUrl' =&gt; 'http://localhost:8888/',
    'server' =&gt; 'localhost',
        'enableCsrfProtection' =&gt; true,
        'defaultWeekStartDay' =&gt; 0,
        'omitScriptNameInUrls' =&gt; 'auto',
        'defaultSearchTermOptions' =&gt; array(
            'subLeft' =&gt; true,
            'subRight' =&gt; true,
        ),
        'cpTrigger' =&gt; 'admin',

    'environmentVariables' =&gt; array(
      'baseUrl'  =&gt; 'http://localhost:8888/',
    ),
    'testToEmailAddress' =&gt; 'dev@email.com',
  ),

  'testurl.com' =&gt; array(
    'siteUrl' =&gt; 'testurl.com',
    'server' =&gt; 'localhost',

        'enableCsrfProtection' =&gt; true,
        'defaultWeekStartDay' =&gt; 0,
        'omitScriptNameInUrls' =&gt; 'auto',
        'defaultSearchTermOptions' =&gt; array(
            'subLeft' =&gt; true,
            'subRight' =&gt; true,
        ),
        'cpTrigger' =&gt; 'admin',

    'environmentVariables' =&gt; array(
      'basePath' =&gt; '/var/www/html/',
      'baseUrl' =&gt; 'http://testurl.com/',
    )
  )
);
</code></pre>

<config><deployment>
Links breaking with double domain
# Links breaking with double domain

(Asked by: username_0 on 2017-04-17)

When calling my links, they're appearing and trying to link like so:

testurl.com/university/testurl.com/university/arizona-state/

Really it should just be 

testurl.com/university/arizona-state/

The line that is generating a category URL:
        

and my general.php:
return array(

  '*' => array(
  ),

  'localhost' => array(
    'devMode' => true,
    'siteUrl' => 'http://localhost:8888/',
    'server' => 'localhost',
        'enableCsrfProtection' => true,
        'defaultWeekStartDay' => 0,
        'omitScriptNameInUrls' => 'auto',
        'defaultSearchTermOptions' => array(
            'subLeft' => true,
            'subRight' => true,
        ),
        'cpTrigger' => 'admin',

    'environmentVariables' => array(
      'baseUrl'  => 'http://localhost:8888/',
    ),
    'testToEmailAddress' => 'dev@email.com',
  ),

  'testurl.com' => array(
    'siteUrl' => 'testurl.com',
    'server' => 'localhost',

        'enableCsrfProtection' => true,
        'defaultWeekStartDay' => 0,
        'omitScriptNameInUrls' => 'auto',
        'defaultSearchTermOptions' => array(
            'subLeft' => true,
            'subRight' => true,
        ),
        'cpTrigger' => 'admin',

    'environmentVariables' => array(
      'basePath' => '/var/www/html/',
      'baseUrl' => 'http://testurl.com/',
    )
  )
);

**Tags:** config, deployment

---

## 3 answers

### Answer by username_1 on 2017-04-17. Score: 2 | Accepted answer

I generally find this snippet to be useful
(isset($_SERVER['HTTPS']) ? 'https://' : 'http://') . $_SERVER['SERVER_NAME']

Especially if you set up a virtual host locally in most situations you can define this in your * and it will work across local/staging/production.
Here's a basic example config:
'*' => [
    'environmentVariables' => [
        'basePath' => '/Users/your/path/to/site/',
        'baseUrl' => (isset($_SERVER['HTTPS']) ? 'https://' : 'http://') . $_SERVER['SERVER_NAME']
    ],
    'enableCsrfProtection' => true,
    'devMode' => true,      
],

'live' => [
     'environmentVariables' => [
        'basePath' => '/srv/different/path/to/site/',
     ],
]

> **Comments:**
> **username_0**: Would you be able to edit this answer and include a snippet of the config file including this line to help others.  

---

### Answer by username_0 on 2017-04-17. Score: 3

Fixed by changing the following line:
'siteUrl' => 'http://testurl.com',


---

### Answer by username_2 on 2021-04-18. Score: 1

Make sure your PRIMARY\_SITE\_URL in your .env file contains the url scheme.
Example :
PRIMARY\_SITE\_URL=http://test.localhost


---

