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

I'm having URLs like:

index.php?q=123&w=456&e=789

and I need to rewrite them in something like:

index/123/456/789

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

 
discard

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.