Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rewrite rules for multilingual website using Wordpress

enter link description hereI know very little about .htaccess and I need an advice.

I'm developing a multilingual website with Wordpress and I will translate the content using some JS magic called Localise.js

With this web app I can translate easily any URL by adding the parameter ?ljs=XX to my url.

So for instance if I want to translate this url http://www.example.com/company into Spanish I will use the url http://www.example.com/company?ljs=es

For SEO purpose, I would like to rewrite the URL into something more meaningful like : http://www.example.com/es/company

So page like :

http://www.example.com/es/company

http://www.example.com/fr/company

http://www.example.com/jp/company

are just pointing to http://www.example.com/company

How could I merge these rules with Wordpress basic rewrite rules?

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

I tried to tweak that solution but without any luck.

Thanks in advance for your time and patience.

Peace.

like image 635
Jk_ Avatar asked Apr 09 '26 09:04

Jk_


1 Answers

Not sure if this will do it for you, there may be a wordpress specific way to handle this using its internal rewrite engine, but with mod_proxy enabled, you can try internally proxying the request to wordpress. The reason for this is because this creates a new request that wordpress would be able to interpret. Otherwise, when you internally rewrite, server variables like $_SERVER['REQUEST_URI'] would be wrong.

So something like:

RewriteRule ^(en|es|fr|jp)/(.*)$ /$2?ijs=$1 [L,QSA,P]

And you'd need to either fill out the (en|es|fr|jp) list to include all the languages you support, or change that regex to ([a-z]{2}). Then you'd add that rule right below RewriteBase /.

like image 195
Jon Lin Avatar answered Apr 13 '26 06:04

Jon Lin



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!