0

I have a multilingual web application that depends on a language code being in the URL.

Example:

example.com/zh-hans/title

The client now wants a new structure:

example.com/cn/title

The problem is the application was built around using zh-hans. As that part of the URL is an argument that is necessary for the application to work properly, changing it would break the application. Also, it's not possible to change this in the application to accommodate. This would take 100s of hours of work to undo.

Is it possible for the browser to show one URL while behind the scenes data is served from the other URL and thus preserve functionality?

The Apache documentation state that:

Assume we have recently renamed the page foo.html to bar.html and now want to provide the old URL for backward compatibility. However, we want that users of the old URL even not recognize that the pages was renamed - that is, we don't want the address to change in their browser.

https://httpd.apache.org/docs/2.4/rewrite/remapping.html (From old to new (internal))

Then, would the solution to this issue be as simple as this?

RewriteEngine  on
RewriteRule    "^/zh-hans/(.+)"  "/cn/$" [PT]
MrWhite
  • 13,315

1 Answers1

0
RewriteEngine  on
RewriteRule    "^/zh-hans/(.+)"  "/cn/$" [PT]

If the "client now wants a new structure: example.com/cn/title" then it looks like your rewrite directive should be the other way round? For example:

RewriteRule    ^/cn/(.+)  /zh-hans/$1 [PT]

You still need to change the visible URL structure in your application to show example.com/cn/title (after all, the client "wants a new structure") which then gets internally rewritten to example.com/zh-hans/title, so that your underlying application can understand it.

However, it is still dependent on your web application reading the URL as intended. If, for instance, it looks at the REQUEST_URI (or equivalent) then it's still going to see example.com/cn/title.

MrWhite
  • 13,315