问题描述
我有大约 400 个 url 将在新版本中更改,出于某些原因,我无法在新网站中重复相同类型的 url 结构.
我的问题是,我可以给 nginx 一个 url 列表(是的,我知道 400 个),然后简单地告诉他每个人都要去另一个 url?
就像我说的 url 结构会有所不同,所以我不能使用任何类型的模式.
提前致谢.
如果您有很长的条目列表,最好将它们保留在 nginx 配置文件之外:
map_hash_bucket_size 256;# 见 http://nginx.org/en/docs/hash.html地图 $request_uri $new_uri {包括/etc/nginx/oldnew.map;# 或任何 nginx 可读的文件}服务器 {听80;server_name your_server_name;如果($new_uri){返回 301 $new_uri;}...}
/etc/nginx/oldnew.map 示例:
/my-old-url/my-new-url;/old.html/new.html;
<块引用>
请务必以;"结束每一行字符!
此外,如果您需要将所有 URL 重定向到另一个主机,您可以使用:
return 301 http://example.org$new_uri;
或者,如果您还需要重定向到另一个端口:
return 301 http://example.org:8080$new_uri;
I have about 400 url that will change in the new version and for some reasons I can't repeat the same type of url structure in the new website.
My question is, can I give a url list to nginx (yeah I know the 400 ones), and tell him simply that each one of them are going to another url?
Like I said the url structure will be different so I can't use any type of pattern.
Thanks in advance.
If you have a very long list of entries, could be a good idea to keep them outside of the nginx configuration file:
map_hash_bucket_size 256; # see http://nginx.org/en/docs/hash.html
map $request_uri $new_uri {
include /etc/nginx/oldnew.map; #or any file readable by nginx
}
server {
listen 80;
server_name your_server_name;
if ($new_uri) {
return 301 $new_uri;
}
...
}
/etc/nginx/oldnew.map sample:
/my-old-url /my-new-url;
/old.html /new.html;
Be sure to end each line with a ";" char!
Moreover, if you need to redirect all URLs to another host, you could use:
return 301 http://example.org$new_uri;
Or, if you also need to redirect to another port:
return 301 http://example.org:8080$new_uri;
这篇关于nginx:如何从给定列表中批量永久重定向?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,WP2