本文介绍了nginx将网址重定向到新模式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我当前正在将博客从Wordpress切换到Ghost.在Ghost前面有Nginx. 迁移后,我认识到旧网址
I'm currently switching my blog from Wordpress to Ghost. There is nginx in front of ghost. After migration i recognized that old urls
domain/2015/10/some-topic被迁移为
domain/some-topic所以日期不见了.无论如何,有一些我不想失去的反向链接,但是我对nginx不太熟悉...所以从旧的url样式重定向到新的url的最佳方法是什么?
So date is gone. Anyway there is some backlinking i don't want to loose, but i'm not so familiar with nginx...So what is the best way to redirect from old url style to new?
我的当前配置如下:
server { listen 80; server_name domain; location / { proxy_set_header X-Real-IP $remote_addr; proxy_set_header HOST $http_host; proxy_set_header X-NginX-Proxy true; proxy_pass 10.240.0.2:2368; proxy_redirect off; } }应该添加什么?我想我需要新的位置,但是它应该是什么样子?
What should be added?. I suppose i need new location but how it should look like?
推荐答案我建议使用地图:
map $uri $redirect_topic { "~^/\d{4}/\d{2}/(?<topic>.*)" $topic; } server { listen 80; server_name domain; if ($redirect_topic) { return 301 $scheme://$host/$redirect_topic; } location / { proxy_set_header X-Real-IP $remote_addr; proxy_set_header HOST $http_host; proxy_set_header X-NginX-Proxy true; proxy_pass 10.240.0.2:2368; proxy_redirect off; } }更多推荐
nginx将网址重定向到新模式
发布评论