nginx redirect url to new pattern

前端 未结 2 1070
深忆病人
深忆病人 2021-01-28 17:40

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         


        
2条回答
  •  南方客
    南方客 (楼主)
    2021-01-28 18:09

    I would recommend using a map:

    map $uri $redirect_topic {
        "~^/\d{4}/\d{2}/(?.*)" $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;
        }
    }
    

提交回复
热议问题