我有多个不同的Query_String重写Apache转换为Nginx:
ServerName oldsite.com RewriteCond %{QUERY_STRING} ^ubb=showflat&Number=662213$ RewriteRule ^/ubbthreads/ubbthreads.php$ http://newsite.com/1/? [R=301,NC,L] RewriteCond %{QUERY_STRING} ^ubb=showflat&Number=662214$ RewriteRule ^/ubbthreads/ubbthreads.php$ http://newsite.com/2/? [R=301,NC,L]
– >
server { listen 80; server_name oldsite.com; location ~ /ubbthreads/{ if ($arg = "ubb=showflat&Number=662213"{ rewrite ^ubbthreads/ubbthreads.php http://newsite.com/1/? permanent; } if ($arg = "ubb=showflat&Number=662214"{ rewrite ^ubbthreads/ubbthreads.php http://newsite.com/2/? permanent; } }
那是正确的方法吗? 有没有另一种方法来做到这一点,如果?
你可能可以使用它的地图。
map $arg_Number $new { 662213 http://newsite.com/1/? 662214 http://newsite.com/2/? }
然后在你的位置
rewrite ^ $new permanent;
请注意,只有当您将每个请求redirect到该位置时,您才能避免。 如果只有当Number是特定的或者设置的时候你需要redirect的话,那么你就不能避免一个更糟糕的情况(只有当某些特定的情况下)你根本不能使用这个地图。