Assuming we want to rewrite URLs in the following format:
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=cont…
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:
And see the same content as if you visited:
example.com/index.php?lang=en&page=cont…
Note that your website's CMS or page/scripting framework may need to be configured to handle the "lang" and "page" parameters properly.
Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss
Asked: 2023-06-07 14:44:34 +0000
Seen: 17 times
Last updated: Jun 07 '23
The content inside my buttons is not visible on the screen.
What causes peep and pop operations to produce invalid outputs?
What does the message "No tests found" from playwright VSCode mean?
Why does SVG fail to display in Safari, but functions properly in Chrome?
How to use hyperlinks in SharePoint List within Teams?
What is the meaning of the build error message "NoClassDefFoundError: org/apache/xpath/XPathAPI"?