Hi,
I am trying to make a 301 redirect like this:
/authors.php?name=xxx ==> /author/xxx
this config solves the problem partially -
location ~ ^/authors.php {
if ($args ~ "name=(.+)" ) {
set $arg_name $1;
rewrite ^/authors\.php "/author/$arg_name"
permanent;
}
}
But the query string remains, and the final location is
/author/xxx?name=xxx
How can i remove the unneeded query string?
Thank you!
Posted at Nginx Forum:
2010/8/12 celevra [email protected]:
permanent;
        }
    }
But the query string remains, and the final location is
/author/xxx?name=xxx
How can i remove the unneeded query string?
You should add a question mark at the end of the rewrite:
location ~ ^/authors.php {
if ($args ~ "name=(.+)" ) {
set $arg_name $1;
rewrite ^/authors\.php "/author/$arg_name?"
permanent;
}
}
there is a cleaner way to write this, but note that this way $arg_name
would not be URL encoded:
location ~ ^/authors.php {
if ($arg_name) {
rewrite ^/authors.php /author/$arg_name? permanent;
}
}
Hello!
On Thu, Aug 12, 2010 at 02:32:56AM -0400, celevra wrote:
permanent;
}
}
But the query string remains, and the final location is
/author/xxx?name=xxx
How can i remove the unneeded query string?
Add trailing “?” to replacement string.
http://wiki.nginx.org/NginxHttpRewriteModule#rewrite
Maxim D.
Thank Maxim D. for take care, I noted, and try now
tyanhly
Posted at Nginx Forum:
Thank Mikhail Mazursky, I try now.
tyanhly
Posted at Nginx Forum: