Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

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 have multiple apache rewrite with different Query_String to convert to nginx:

 RewriteCond %{QUERY_STRING} ^ubb=showflat&Number=662213$ 
 RewriteRule ^/ubbthreads/ubbthreads.php$ [R=301,NC,L]
 RewriteCond %{QUERY_STRING} ^ubb=showflat&Number=662214$ 
 RewriteRule ^/ubbthreads/ubbthreads.php$ [R=301,NC,L]


server {
    listen       80;
    location ~ /ubbthreads/{
        if ($arg = "ubb=showflat&Number=662213"{
        rewrite ^ubbthreads/ubbthreads.php permanent;
        if ($arg = "ubb=showflat&Number=662214"{
        rewrite ^ubbthreads/ubbthreads.php permanent;

Is that the correct way ? Is there another way to do this without if ?

share|improve this question
up vote 1 down vote accepted

You might be able to use a map for it.

map $arg_Number $new {

and then in your location

rewrite ^ $new permanent;

Do note that you can only avoid the if when you redirect every request to that location. If you need to redirect only when Number is something specific or if it's set then you cannot avoid an if and in worse case scenario (only when something specific) you can't use the map at all.

share|improve this answer
Thanks, it worked, note that the trailing "?" has to be in the rewrite and not in the map: rewrite ^ $new? permanent; – Bastien974 Feb 15 '13 at 19:28

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.