I am working on an existing CMS, and now there is a task to localize the site (America and Canada), actually any URL for America will look like (relative to the root) /about-us/ , and for Canada - /ca/about-us/ , i.e. all the same urls, only with the prefix /ca/ . At first there was the idea to pass all relative links through the function, which will add this prefix, but the disadvantage of this approach is that there is too much work to do to rewrite all URLs in all templates (and in some .js files).

Actually, the possibility of changing the ROOT of the site, depending on the incoming URL, is of interest, so that all relative links now have the correct prefix.

Now all the incoming logic is implemented on one rule:

RewriteRule ^(ca)(?:/([A-Za-z0-9-/]+)?)?$ /$2?localization=$1 [NC,L,QSA]

Actually, maybe there is some kind of RewriteCond that implements such logic, or a different approach?

  • so you mean by root the directory with the files on the server or something else. - Naumov
  • @Naumov Hmm, I do not even know. That place where all relative links start from. - tekken

0