Answers.Body: <p>Craft doesn't usually perform redirects in the frontend based on the domain. If the current domain matches the <strong>Base URL</strong>, Craft will load that site and attempt to display the correct route for that site and the requested path. If the domain doesn't match any defined sites, it will fall back to the default site.</p>
  <p>Redirects can happen in multiple places:</p>
  <ol>
  <li>Your server config (for example, the Apache or Nginx site config or an <code>.htaccess</code> file in your web root).</li>
  <li>Any <a href="https://craftcms.com/docs/4.x/dev/tags.html#redirect" rel="nofollow noreferrer"><code>{% redirect %}</code> tags</a> in your templates.</li>
  <li>PHP code in custom modules or plugins.</li>
  </ol>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2024-01-10T08:52:03.490Z
Answers.LastActivityDate: 2024-01-10T08:52:03.490Z
Answers.UserDisplayName: MoritzLost
Body: <p>I have a craft site that was in developement.
  the main site was linked just to an IP address
  the secondary site was linked to a url.
  Everything was working perfectly, I could see each site individually and make changes to both from the dashboard at the primary site.
  When we were ready to go live, I edited the <code>.env</code> file and changed the urls to the 2 new domains.
  Now when I try to load the primary site or dashboard, everything is fine, however when I try to load the content of the secondary site by visiting the secondary URL it loads the content of the primary URL but the actual url is correct and shows the secondary url.</p>
  <p>So, going to <code>https://example1.com</code> loads content correctly.</p>
  <p>Going to <code>https://example2.com</code>leaves <code>https://example2.com</code> in the URL bar but shows content of <code>https://example1.com</code>.</p>
  <p>the only changes I made where here in the <code>.env</code> file.</p>
  <pre><code>APP_URL=ip address
  APP_URL_ST=https://example1.com
  
  APP_URL=https://newexample1.com
  APP_URL_ST=https://newexample2.com
  </code></pre>
  <p>everything at <code>newexample1.com</code> works fine.</p>
  <p>Primary site:</p>
  <p><a href="https://i.sstatic.net/xqxy7.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/xqxy7.png" alt="enter image description here" /></a></p>
  <p>Secondary Site</p>
  <p><a href="https://i.sstatic.net/sTjPb.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/sTjPb.png" alt="enter image description here" /></a></p>
  <p><strong>As an update</strong> it's not this way for everyone.  Some people see both sites correctly but others don't.  People who can't see it correctly have cleared caches, gone incognito, and tried different browsers.</p>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2024-01-06T14:57:02.983Z
Comments.Text: Please post your website configuration (Settings -> Websites) for both sites. When you visit the secondary domain, are you **redirected** to site one (i.e. you see the primary domain in your browser) or does the URL bar still show the secondary domain, but Craft loads the primary site?
Comments.UserDisplayName: MoritzLost
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2024-01-08T22:53:28.793Z
Comments.Text: @MoritzLost.  I added the screenshots of the pages.  I had settings "sites" not "websites" but maybe that's because I'm still on 3.9.6
Comments.UserDisplayName: rudtek
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2024-01-09T15:26:01.830Z
Comments.Text: Hm, looks correct to me. Double check the server configuration (any redirects in a htaccess file, Apache or Nginx config?), and make sure to clear all server-side caches in Utilities -> Caches. Also, check again your templates to see if there are any redirects happening there.
Comments.UserDisplayName: MoritzLost
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2024-01-09T18:20:58.350Z
Comments.Text: @MoritzLost.  You're good! it was my .htacess file.  Do you want to post as an answer?  I needed to add a re-direct from my www to non.
Comments.UserDisplayName: rudtek
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2024-01-10T08:52:58.423Z
Comments.Text: Ah, great  I've added an answer accordingly.
Comments.UserDisplayName: MoritzLost
Tags: <migration><multi-environment>
Title: My secondary site keeps going back to the primary url after changing urls
ThreadText: # My secondary site keeps going back to the primary url after changing urls
  
  (Asked by: username_0 on 2024-01-05)
  
  I have a craft site that was in developement.
  the main site was linked just to an IP address
  the secondary site was linked to a url.
  Everything was working perfectly, I could see each site individually and make changes to both from the dashboard at the primary site.
  When we were ready to go live, I edited the `.env` file and changed the urls to the 2 new domains.
  Now when I try to load the primary site or dashboard, everything is fine, however when I try to load the content of the secondary site by visiting the secondary URL it loads the content of the primary URL but the actual url is correct and shows the secondary url.
  
  So, going to `https://example1.com` loads content correctly.
  
  Going to `https://example2.com`leaves `https://example2.com` in the URL bar but shows content of `https://example1.com`.
  
  the only changes I made where here in the `.env` file.
  
  ```
  APP_URL=ip address
  APP_URL_ST=https://example1.com
  
  APP_URL=https://newexample1.com
  APP_URL_ST=https://newexample2.com
  
  ```
  
  everything at `newexample1.com` works fine.
  
  Primary site:
  
  [![enter image description here](https://i.sstatic.net/xqxy7.png)](https://i.sstatic.net/xqxy7.png)
  
  Secondary Site
  
  [![enter image description here](https://i.sstatic.net/sTjPb.png)](https://i.sstatic.net/sTjPb.png)
  
  **As an update** it's not this way for everyone. Some people see both sites correctly but others don't. People who can't see it correctly have cleared caches, gone incognito, and tried different browsers.
  
  **Tags:** migration, multi-environment
  
  > **Comments:**
  > **username_1**: Please post your website configuration (Settings -> Websites) for both sites. When you visit the secondary domain, are you **redirected** to site one (i.e. you see the primary domain in your browser) or does the URL bar still show the secondary domain, but Craft loads the primary site?  
  > **username_0**: @username_1.  I added the screenshots of the pages.  I had settings "sites" not "websites" but maybe that's because I'm still on 3.9.6  
  > **username_1**: Hm, looks correct to me. Double check the server configuration (any redirects in a htaccess file, Apache or Nginx config?), and make sure to clear all server-side caches in Utilities -> Caches. Also, check again your templates to see if there are any redirects happening there.  
  > **username_0**: @username_1.  You're good! it was my .htacess file.  Do you want to post as an answer?  I needed to add a re-direct from my www to non.  
  > **username_1**: Ah, great  I've added an answer accordingly.  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2024-01-10. Score: 2 | Accepted answer
  
  Craft doesn't usually perform redirects in the frontend based on the domain. If the current domain matches the **Base URL**, Craft will load that site and attempt to display the correct route for that site and the requested path. If the domain doesn't match any defined sites, it will fall back to the default site.
  
  Redirects can happen in multiple places:
  
  1. Your server config (for example, the Apache or Nginx site config or an `.htaccess` file in your web root).
  2. Any [`{% redirect %}` tags](https://craftcms.com/docs/4.x/dev/tags.html#redirect) in your templates.
  3. PHP code in custom modules or plugins.
  
  
  ---
  
  