MODX Community

Lingua SEO Friendly URLs

About a year and a half ago sjmclean asked this question. I’m trying to achieve the same thing.

When switching languages, I get the language URLs as per following examples:

https://mydomain.com?lang=en (for English)
https://mydomain.com?lang=fr (for French)
etc …

What I am looking to achieve is to switch these to:

https://mydomain.com/en (for English)
https://mydomain.com/fr (for French)
etc …

Jimf3000 provided this response, but no specifics.

jimf3000 Reply #5, 1 year, 4 months ago

Hi sjmclean,

I've used the Lingua extra on quite a few projects and it works great.

Like aaronkent, I use .htaccess, but with the addition of Ajax.

1. By using .htaccess to allow for 'example.com/{country_code}/', you can grab the {country_code} by exploding $_SERVER['REQUEST_URI'] and checking to see if the {country_code} matches the current MODx cultureKey.
2. If they don't match, you can just do an Ajax post to example.com?lang={country_code} and refresh your page.

I’m looking for some example .htaccess code to accomplish this. Anybody have something to share?

Thanks.