Answers.Body: <p>So!!!! I was getting confused about the various craft properties pertaining to urls, and I thought that even if I grab the path, that it would include the region segment, but surprise! {{ craft.request.path }} grabs the remaining portion of the url, after the region segment! So, I can use code that I've written above and I only need to add:</p>
  
  <pre><code>&lt;!-- language: lang-twig --&gt;
  
      /{{ craft.request.path }}
  </code></pre>
  
  <p>Example: </p>
  
  <pre><code>&lt;!-- language: lang-twig --&gt;
  
      &lt;form action="" name="dropdown"&gt;
          &lt;select name="country-select"  id="country-select" class="form-control" onchange="location = this.value;" autocomplete="off"&gt;&gt;
              {% set locales = craft.i18n.getSiteLocaleIds() %}
              {% set locale = craft.locale %}
              {% for loc in locales %}
                  {# checking if current loop has active locale #}
                  {% set isHome = (loc == locale) %}
                  {% if isHome %}
  
                      {% if loc == "en" %}
                          &lt;option value="/{{ loc | replace({'en': 'eu'}) }}/{{ craft.request.path }}" selected&gt;Europe&lt;/option&gt;   
  
                      {% else %}
                          {% set subTags = locale|split('_') %}
                          {% set territory = subTags|length &gt; 1 ? craft.i18n.getLocaleData(craft.locale).getTerritory(subTags|last) : '' %}  
                              &lt;option value="/{{ loc | replace({'en': ''}) | trim('_') }}/{{ craft.request.path }}" selected&gt;{% if territory %}{{ territory }}{% endif %}&lt;/option&gt;  
  
                      {% endif %}
  
                  {% else %}
  
                      {% if loc == "en" %}
                          &lt;option value="/{{ loc | replace({'en': 'eu'}) }}/{{ craft.request.path }}"&gt;EU&lt;/option&gt;   
                      {% else %}
                          &lt;option value="/{{ loc | replace({'en': ''}) | trim('_') }}/{{ craft.request.path }}"&gt;{{ loc | replace({'en': ''}) | trim('_') | upper }} &lt;/option&gt;   
                      {% endif %}
  
                  {% endif %}
  
              {% endfor %}
          &lt;/select&gt;
      &lt;/form&gt;
  </code></pre>
  
  <p>Yay!! I wanted to share my answer because I've been working on this issue for a few days and couldn't find a solution anywhere. Maybe it will help someone else that runs into this issue when building a multi-country website with Craft. Cheers!</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-11-19T20:42:48.677Z
Answers.LastActivityDate: 2017-11-19T20:42:48.677Z
Answers.UserDisplayName: hcone5006
Body: <p>How would you go about changing one segment of the current url? I have a select in the footer that you can click on a country name and then it redirects you to the homepage of that country version of the website. </p>
  
  <pre><code>&lt;!-- language: lang-twig --&gt;
  &lt;form action="" name="dropdown"&gt;
      &lt;select name="country-select"  id="country-select" class="form-control" onchange="location = this.value;" autocomplete="off"&gt;&gt;
          {% set locales = craft.i18n.getSiteLocaleIds() %}
          {% set locale = craft.locale %}
          {% for loc in locales %}
              {# checking if current loop has active locale #}
              {% set isHome = (loc == locale) %}
              {% if isHome %}
  
                  {% if loc == "en" %}
                      &lt;option value="/{{ loc | replace({'en': 'eu'}) }}" selected&gt;Europe&lt;/option&gt;   
  
                      {% set myJs %}
  
                          var currentCountryLocale = "Europe";
                          var currentCountryLocale = "{{ loc | replace({'en': 'eu'}) | trim('_') }}";
  
                      {% endset %}
  
                      {% includeJs myJs %}
  
                  {% else %}
                      {% set subTags = locale|split('_') %}
                      {% set territory = subTags|length &gt; 1 ? craft.i18n.getLocaleData(craft.locale).getTerritory(subTags|last) : '' %}  
                          &lt;option value="/{{ loc | replace({'en': ''}) | trim('_') }}" selected&gt;{% if territory %}{{ territory }}{% endif %}&lt;/option&gt;  
  
                      {% set myJs %}
  
                          var currentCountryName = "{{ territory }}";
                          var currentCountryLocale = "{{ loc | replace({'en': ''}) | trim('_') }}";
  
  
                      {% endset %}
  
                      {% includeJs myJs %}
  
                  {% endif %}
  
              {% else %}
  
                  {% if loc == "en" %}
                      &lt;option value="/{{ loc | replace({'en': 'eu'}) }}"&gt;EU&lt;/option&gt;   
                  {% else %}
                      &lt;option value="/{{ loc | replace({'en': ''}) | trim('_') }}"&gt;{{ loc | replace({'en': ''}) | trim('_') | upper }} &lt;/option&gt;   
                  {% endif %}
  
              {% endif %}
  
          {% endfor %}
      &lt;/select&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>I have been trying to figure out how to switch only the country/region part of the url, which is segment(2), but all of my experiments so far have been extremely complicated and confusing and I haven't found a good solution yet. Am I missing something? There must be a more efficient way to accomplish this, as it's probably not a good idea to wrap conditionals inside of conditionals inside of more conditionals. </p>
  
  <p>I also have the added complexity of needing to include a continent (Europe) as one of the versions of the website, for which I'm using the "en" locale, as you can see in the bit of code above.</p>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2017-11-16T03:50:56.630Z
Comments.Text: Glad you got it sorted, @hcone5006 and thanks for sharing what worked for you! Would you mind adding your solution as an official answer instead of an edit to your original question?
Comments.UserDisplayName: Brad Bell
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2017-11-19T20:44:42.890Z
Comments.Text: Thanks, @BradBell I've done that as you suggested. Hope it helps someone else!
Comments.UserDisplayName: hcone5006
Tags: <localization><multi-environment><segments>
Title: Is it possible to change one segment of the current url and keep the rest of it the same in a cleaner way?
ThreadText: # Is it possible to change one segment of the current url and keep the rest of it the same in a cleaner way?
  
  (Asked by: username_0 on 2017-11-16)
  
  How would you go about changing one segment of the current url? I have a select in the footer that you can click on a country name and then it redirects you to the homepage of that country version of the website.
  
  ```
  <!-- language: lang-twig -->
  <form action="" name="dropdown">
      <select name="country-select"  id="country-select" class="form-control" onchange="location = this.value;" autocomplete="off">>
          {% set locales = craft.i18n.getSiteLocaleIds() %}
          {% set locale = craft.locale %}
          {% for loc in locales %}
              {# checking if current loop has active locale #}
              {% set isHome = (loc == locale) %}
              {% if isHome %}
  
                  {% if loc == "en" %}
                      <option value="/{{ loc | replace({'en': 'eu'}) }}" selected>Europe</option>   
  
                      {% set myJs %}
  
                          var currentCountryLocale = "Europe";
                          var currentCountryLocale = "{{ loc | replace({'en': 'eu'}) | trim('_') }}";
  
                      {% endset %}
  
                      {% includeJs myJs %}
  
                  {% else %}
                      {% set subTags = locale|split('_') %}
                      {% set territory = subTags|length > 1 ? craft.i18n.getLocaleData(craft.locale).getTerritory(subTags|last) : '' %}  
                          <option value="/{{ loc | replace({'en': ''}) | trim('_') }}" selected>{% if territory %}{{ territory }}{% endif %}</option>  
  
                      {% set myJs %}
  
                          var currentCountryName = "{{ territory }}";
                          var currentCountryLocale = "{{ loc | replace({'en': ''}) | trim('_') }}";
  
                      {% endset %}
  
                      {% includeJs myJs %}
  
                  {% endif %}
  
              {% else %}
  
                  {% if loc == "en" %}
                      <option value="/{{ loc | replace({'en': 'eu'}) }}">EU</option>   
                  {% else %}
                      <option value="/{{ loc | replace({'en': ''}) | trim('_') }}">{{ loc | replace({'en': ''}) | trim('_') | upper }} </option>   
                  {% endif %}
  
              {% endif %}
  
          {% endfor %}
      </select>
  </form>
  
  ```
  
  I have been trying to figure out how to switch only the country/region part of the url, which is segment(2), but all of my experiments so far have been extremely complicated and confusing and I haven't found a good solution yet. Am I missing something? There must be a more efficient way to accomplish this, as it's probably not a good idea to wrap conditionals inside of conditionals inside of more conditionals.
  
  I also have the added complexity of needing to include a continent (Europe) as one of the versions of the website, for which I'm using the "en" locale, as you can see in the bit of code above.
  
  **Tags:** localization, multi-environment, segments
  
  > **Comments:**
  > **username_1**: Glad you got it sorted, @username_0 and thanks for sharing what worked for you! Would you mind adding your solution as an official answer instead of an edit to your original question?  
  > **username_0**: Thanks, @username_1 I've done that as you suggested. Hope it helps someone else!  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_0 on 2017-11-19. Score: 1 | Accepted answer
  
  So!!!! I was getting confused about the various craft properties pertaining to urls, and I thought that even if I grab the path, that it would include the region segment, but surprise! {{ craft.request.path }} grabs the remaining portion of the url, after the region segment! So, I can use code that I've written above and I only need to add:
  
  ```
  <!-- language: lang-twig -->
  
      /{{ craft.request.path }}
  
  ```
  
  Example:
  
  ```
  <!-- language: lang-twig -->
  
      <form action="" name="dropdown">
          <select name="country-select"  id="country-select" class="form-control" onchange="location = this.value;" autocomplete="off">>
              {% set locales = craft.i18n.getSiteLocaleIds() %}
              {% set locale = craft.locale %}
              {% for loc in locales %}
                  {# checking if current loop has active locale #}
                  {% set isHome = (loc == locale) %}
                  {% if isHome %}
  
                      {% if loc == "en" %}
                          <option value="/{{ loc | replace({'en': 'eu'}) }}/{{ craft.request.path }}" selected>Europe</option>   
  
                      {% else %}
                          {% set subTags = locale|split('_') %}
                          {% set territory = subTags|length > 1 ? craft.i18n.getLocaleData(craft.locale).getTerritory(subTags|last) : '' %}  
                              <option value="/{{ loc | replace({'en': ''}) | trim('_') }}/{{ craft.request.path }}" selected>{% if territory %}{{ territory }}{% endif %}</option>  
  
                      {% endif %}
  
                  {% else %}
  
                      {% if loc == "en" %}
                          <option value="/{{ loc | replace({'en': 'eu'}) }}/{{ craft.request.path }}">EU</option>   
                      {% else %}
                          <option value="/{{ loc | replace({'en': ''}) | trim('_') }}/{{ craft.request.path }}">{{ loc | replace({'en': ''}) | trim('_') | upper }} </option>   
                      {% endif %}
  
                  {% endif %}
  
              {% endfor %}
          </select>
      </form>
  
  ```
  
  Yay!! I wanted to share my answer because I've been working on this issue for a few days and couldn't find a solution anywhere. Maybe it will help someone else that runs into this issue when building a multi-country website with Craft. Cheers!
  
  
  ---
  
  