Contents
How does Apache rewriterule deal with query strings?
At first look, the way Apache mod_rewrite module deals with query strings can be a little confusing. From the RewriteRule documentation: qsappend|QSA’ (query string append) This flag forces the rewrite engine to append a query string part of the substitution string to the existing string, instead of replacing it.
What should the rewrite rule look like in Apache?
Our rewrite rule should looks like this: According to the official documentation, you would expect the following behavior: However, if you don’t append something new, then the original query is passed through the rules unchanged by default.
What happens if you don’t append a query string?
According to the official documentation, you would expect the following behavior: However, if you don’t append something new, then the original query is passed through the rules unchanged by default. If you want to discard the original query string you must append an empty question mark at the end of the rule.
How to pass get parameters to rewritten url?
How to pass GET parameters to rewritten URL? What this does is, if someone visits http://example.com/search/test the URI that is really processed is http://www.example.com/search.php?q=test. Now, if I try to pass an extra random GET parameter to my rewritten URL, the parameter is ignored.
When to use the QSA flag in rewriterule?
When the replacement URI contains a query string, the default behavior of RewriteRule is to discard the existing query string, and replace it with the newly generated one. Using the [QSA] flag causes the query strings to be combined. Consider the following rule:
What happens when a rewriterule does not match?
That is, if the rule matches, then it is processed as usual and control moves on to the next rule. However, if it does not match, then the next rule, and any other rules that are chained together, are skipped. The [CO], or [cookie] flag, allows you to set a cookie when a particular RewriteRule matches.