But the q parameter is empty on redirection.
I don't see that problem. When I test the configuration as written, it creates a redirection loop because the original keywords='value'
is appended to the rewritten URI.
You can prevent rewrite
from including any original parameters by appending a ?
to the rewritten URI.
For example:
rewrite ^ /search?q=$arg_keywords? permanent;
See this document for details.