1 | initial version |
Assuming we want to rewrite URLs in the following format:
example.com/en/contact-us
Where "en" is the virtual language folder and "contact-us" is the page name, and we want it to be rewritten to:
example.com/index.php?lang=en&page=contact-us
Here are the steps to achieve this using htaccess:
Create a new file named ".htaccess" in your website's root folder.
Add the following code to the file:
RewriteEngine On RewriteRule ^([\w-]+)/([\w-]+)$ index.php?lang=$1&page=$2 [L]
This code enables the RewriteEngine and sets up a rule to match any URL that follows the format "virtual-language-folder/page-name". It then rewrites the URL to "index.php?lang=virtual-language-folder&page=page-name".
Save the file and upload it to your website's root folder.
Test the rewrite by visiting a URL in the expected new format. For example, if you have an English version of the "contact us" page, you should be able to visit:
example.com/en/contact-us
And see the same content as if you visited:
example.com/index.php?lang=en&page=contact-us
Note that your website's CMS or page/scripting framework may need to be configured to handle the "lang" and "page" parameters properly.