I am trying to build a multilingual website with Drupal.
I like to have the following url format
http://domain/[language]/[node id]
so I added the following rule to .htaccess for testing purpose
RewriteRule ^jpn/[0-9]$ jpn.html
The problem is that the rule is overwritten by the following rule
RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]
How do I have multiple rewrite rules?
htaccess rewrite rules can be used to direct requests for one subdirectory to a different location, such as an alternative subdirectory or even the domain root. In this example, requests to http://mydomain.com/folder1/ will be automatically redirected to http://mydomain.com/folder2/.
In your rewrite, the ^ signifies the start of the string, the (. *) says to match anything, and the $ signifies the end of the string. So, basically, it's saying grab everything from the start to the end of the string and assign that value to $1.
Rewrite rules also include the ability to use regex matching on the URI before it is executed. In this case, a RewriteCond is not necessary and the condition can be rolled directly into the rule. RewriteRule takes two parameters. A condition based on the request URI on which to execute the Rule.
For instance, to rewrite according to the REMOTE_USER variable from within the per-server context ( httpd. conf file) you must use %{LA-U:REMOTE_USER} - this variable is set by the authorization phases, which come after the URL translation phase (during which mod_rewrite operates).
Your second RewriteRule
has the L Flag
set, which means that if the rule matches, no further rules will be processed.
If you want your first rule to also stop any further processing, add the L Flag to it as well.
RewriteRule ^jpn/[0-9]$ jpn.html [L]
Also make sure that your second rule is listed last, because it matches everything (.*) and thus, Apache will never see any other rule after it.
Edited: the L Flag URL
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With