Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

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

1 Answer 1

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.