nginx将网址重定向到新模式

编程入门 行业动态 更新时间:2024-10-23 02:47:43
本文介绍了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将网址重定向到新模式

本文发布于:2023-11-01 11:48:06,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1549261.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:到新   重定向   模式   网址   nginx

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!