0

I'm using wordpress. I have query string functionally that displays the content in the correct language.

Example urls

example.com/terms/?lang=en
example.com/terms/?lang=es
example.com/terms/?lang=fr
example.com/terms/?lang=db

The code below grabs the query string value[lang code] and the API uses it to show the correct language.

<script type="text/javascript" charset="UTF-8">   
  var langCodeSearch = new URLSearchParams(window.location.search);
  var langCode = Object.fromEntries(langCodeSearch.entries());

              
   Api.Initialized.then(function() {
    Api.LoadContent(["https://url-to-api-that-has-content.json"], langCode.lang //**language declaration need to happen here**);
              });
</script>

The above code works great but would it be possible to have the same functionally but using the following URL structure?

example.com/terms/en
example.com/terms/es
example.com/terms/fr
example.com/terms/gb

I want to display content based on the last part of the URLs.

Tcmxc
  • 481
  • 1
  • 7
  • 23
  • 1
    Yes, but that means you will need to have some kind of server-side redirect, since those URLs actually will navigate to specific pages instead of to the same page with a different query string. – Terry Sep 10 '21 at 06:51
  • 2
    As addition to the previous comment this is usually a very small change but it depends on the webserver. For Apache httpd you can use a `.htaccess` file. – jabaa Sep 10 '21 at 07:40
  • @jabaa any examples you can point me to? – Tcmxc Sep 10 '21 at 07:57
  • @Terry So the server side redirect will allow me to use urls like example.com/terms/es ? – Tcmxc Sep 10 '21 at 08:03
  • [How to rewrite url with htaccess?](https://stackoverflow.com/questions/38564133/how-to-rewrite-url-with-htaccess) – jabaa Sep 10 '21 at 08:53
  • Many CMS handle this problem with a preconfigured htaccess file to achieve the same behavior you want. [Here](https://docs.joomla.org/Preconfigured_htaccess) is the htaccess of Joomla. – jabaa Sep 10 '21 at 08:58
  • [htaccess redirect for Angular routes](https://stackoverflow.com/questions/22739455/htaccess-redirect-for-angular-routes) – jabaa Sep 10 '21 at 09:00

0 Answers0