B
B
Barrakuda742018-03-28 18:26:31
Apache HTTP Server
Barrakuda74, 2018-03-28 18:26:31

How does the [QSA] flag in mod_rewrite work?

Is it written somewhere in the official docs that the [QSA] flag itself adds an aspersand (&) to the existing parameters? I know that it seems to be adding, and if we prepare a string for the parameters from {query_string} in the second argument of RewriteRule by manually writing '&', we will get a double ampersand, but it's not written anywhere about it, it's just written that the query parameters are stored there, however not a word about the ampersand.
And the second question I encountered:
Everywhere they write that "If the [QSA] flag was specified, the query parameters will be added to the beginning of % {QUERY_STRING}."
But with the request " site.ru/news/?id=4 " and the rule " RewriteRule ^news/$ index.php/?type=news [QSA]", we see that it seems like parameters (id=4) are added to the end of %{QUERY_STRING} (type=news), and the final query_string is equal to "type=news&id=4". So are they added to the beginning or to the end? Or under % {QUERY_STRING} here we mean exactly the user's parameters, and "parameters" are those that are written in the second argument of RewriteRule:

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Viktor Taran, 2018-03-29
@shambler81

you did not take into account the fact that this is a GET and it is not part of the url and therefore does not fall into your condition.
# 301 --- site.ru/news/?id=4 => site.ru/index.php/?type=nes

RewriteCond %{QUERY_STRING} (^|&)id\=4($|&)
RewriteRule ^news/$ /index.php/?type=nes [L,R=301]

Notice that at the top I choose and ? and & which, in turn, you can not add.
I think it's better for you to do the initial settings here https://donatstudios.com/RewriteRule_Generator , and then add your conditions.
Also, if you need to select a part of the request gaiters and substitute it in the rule, then instead of $1, use %1

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question