nginx将网址重定向到新模式 [英] nginx redirect url to new pattern
本文介绍了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
http://domain.org/2015/10/some-topic
被迁移为
http://domain.org/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.org;
location / {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header HOST $http_host;
proxy_set_header X-NginX-Proxy true;
proxy_pass http://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.org;
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 http://10.240.0.2:2368;
proxy_redirect off;
}
}
这篇关于nginx将网址重定向到新模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文