Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm having URLs like:


and I need to rewrite them in something like:


without using "if".

So far I've tried:

location / {
    rewrite ^/index.php\?q=(.*)&w=(.*)&e=(.*)$ /index/$1/$2/$3;

But it doesn't work. Any ideas?

share|improve this question
up vote 1 down vote accepted

The short answer is you can't without using if.

The long answer is regex in the rewrite syntax only matchs the URI.

Try something like this:

    location /index.php {
        if ($args ~ "^q=(.*)&w=(.*)&e=(.*)") {
            set $arg_q $1;
            set $arg_w $2;
            set $arg_e $3;
            rewrite_log on;
        rewrite ^ /index/$arg_q/$arg_w/$arg_e last;
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.