This does not answer the question -- please read the comment with more information I am leaving this answer to host other variants of rewriting viable for other situations.
You can do it easier:
# At "server" level, NOT in "location"
rewrite ^/forum/index.php
/forum/vbseo301.php?action=thread&oldid=$arg_topic?
last;
The ? suffix tells Nginx to not append original arguments to the new URL.
Sidenote
By the way, if you are doing static mapping of one set of IDs to another, there is a more effective solution:
http {
map $arg_topic $new_topic_id {
default 1;
2 3;
4 65;
}
server {
# some directives (server_name, listen, etc.) omitted
rewrite ^/forum/index.php /forum/new.php?topic=$new_topic_id? last;
# locations omitted
}
}
map
takes the first parameter (topic
from query string in this case) and does a lookup through the table. It then assigns the result to the second parameter (new_topic_id
). Two benefits:
- The lookup is very effective, as Nginx creates a hash table.
- The lookup occurs only when you are going to use
new_topic_id
(lazy evaluation)