title: PHP - Replace subfolder in link (in order to change language)
body: <p>This is my first post on this forum, so please forgive any of my unintentional errors.</p>
  
  <p>So, let me try to explain what my problem is:</p>
  
  <p>I have a two language website with a folder structure like this:</p>
  
  <p>mywebsite/ru (russian)
  and
  mywebsite/en (english)</p>
  
  <p>When I'm on the russian version of the website, the links to all categories look like this:</p>
  
  <p>subdomain.domain.com/ru/clients/myclient, 
  subdomain.domain.com/ru/services/myservice
  etc</p>
  
  <p>and when I'm on the english version of the website, the links look the same, the only difference being the /en/ subfolder instead of the /ru/ subfolder:</p>
  
  <p>subdomain.domain.com/en/clients/myclient, 
  subdomain.domain.com/en/services/myservice</p>
  
  <p>What I'd like to do, is have two links in the website's header, one for english and one for russian, and these links should automatically switch the language to the english/russian version, of the current page.</p>
  
  <p>So, if I'm on subdomain.domain.com/ru/services/myservice and click the english link, I want to be redirected to subdomain.domain.com/en/services/myservice
  Or, if I'm on </p>
  
  <p>So if i'm on subdomain.domain.com/ru/clients/myclient and click the english link, I want to be redirected to subdomain.domain.com/en/clients/myclient</p>
  
  <p>So basically, I need a php script (or javascript, if it's easier) that will keep the existing link and changes the /ru/ part to /en/ and viceversa.</p>
  
  <p>I tried searching the web for a solution but can't find one that actually works for me.
  Thank you very much!</p>