<p>Maybe it's just something like this:</p>
<pre><code>{% set enSite = craft.app.getSites().getSiteByHandle('en') %}
{% set frSite = craft.app.getSites().getSiteByHandle('fr') %}
{% set switchSiteUrl = currentSite.handle == 'en' ? frSite.baseUrl ~ craft.app.request.url|slice(1) : enSite.baseUrl ~ craft.app.request.url|slice(4)  %}
&lt;a href=&quot;{{ switchSiteUrl }}&quot;&gt;
  Other Site
&lt;/a&gt;
</code></pre>

CC BY-SA 4.0
2023-02-19T07:19:21.653Z
2023-02-19T07:19:21.653Z
supazu
<p>Not sure how you feel about plugins, but we've built one called <a href="https://plugins.craftcms.com/site-switcher" rel="nofollow noreferrer">Site Switcher</a> to do exactly this.</p>
<p>Using the plugin, it would look something like this...</p>
<pre><code>{# Recognize translated slugs #}
{% set element = (category ?? entry ?? null) %}

{# Identify other site #}
{% set otherSite = currentSite.handle == 'en' ? 'fr' : 'en' %}

&lt;a href=&quot;{{ siteSwitcher(otherSite, element) }}&quot;&gt;
  Other Site
&lt;/a&gt;
</code></pre>

CC BY-SA 4.0
2023-02-21T20:09:49.857Z
2023-02-21T20:09:49.857Z
Lindsey D
<p>This one has been asked many, many times but lots of the solutions are a bit over the top for me.</p>
<p>I have two sites: English and French. URLs are <code>mysite.com</code> and <code>mysite.com/fr</code>.</p>
<p>If I'm on <code>mysite.com/news/article-1</code> I want a simple link to <code>mysite.com/fr/news/article-1</code>, and vice versa.</p>
<p>The problem I have is getting the current URL after the language segment (ie I just want <code>news/article-1</code>). I would use <code>craft.app.request.url</code> but it includes the <code>fr</code> when on the French site.</p>
<p>Does anyone have a solution for this that doesn't involve about 20 lines of code?</p>

<sites>
Simple site switcher
# Simple site switcher

(Asked by: username_0 on 2023-02-19)

This one has been asked many, many times but lots of the solutions are a bit over the top for me.

I have two sites: English and French. URLs are `mysite.com` and `mysite.com/fr`.

If I'm on `mysite.com/news/article-1` I want a simple link to `mysite.com/fr/news/article-1`, and vice versa.

The problem I have is getting the current URL after the language segment (ie I just want `news/article-1`). I would use `craft.app.request.url` but it includes the `fr` when on the French site.

Does anyone have a solution for this that doesn't involve about 20 lines of code?

**Tags:** sites


---

## 2 answers

### Answer by username_0 on 2023-02-19. Score: 1 | Accepted answer

Maybe it's just something like this:
{% set enSite = craft.app.getSites().getSiteByHandle('en') %}
{% set frSite = craft.app.getSites().getSiteByHandle('fr') %}
{% set switchSiteUrl = currentSite.handle == 'en' ? frSite.baseUrl ~ craft.app.request.url|slice(1) : enSite.baseUrl ~ craft.app.request.url|slice(4)  %}

  Other Site


---

### Answer by username_1 on 2023-02-21. Score: 1

Not sure how you feel about plugins, but we've built one called Site Switcher to do exactly this.
Using the plugin, it would look something like this...
{# Recognize translated slugs #}
{% set element = (category ?? entry ?? null) %}

{# Identify other site #}
{% set otherSite = currentSite.handle == 'en' ? 'fr' : 'en' %}


  Other Site


---

