使用nginx在旧网址中使用+重写规则

时间:2013-12-06 14:14:07

标签: nginx rewrite

我正在将一堆用Gallery2托管的照片移动到Zenfolio托管的新子域。我正在尝试从旧域重定向到新域,以获得更受欢迎的相册。不幸的是,G2使用带有空格的专辑名称中的+,而Nginx似乎没有将它们重定向到适当的位置。

这是我正在使用的示例配置。任何帮助表示赞赏!

server {
    listen   80; ## listen for ipv4; this line is default and implied
    listen   [::]:80; ## listen for ipv6

keepalive_timeout   70;

    # Make site accessible from http://localhost/
    server_name old.domain.com;
    root /var/www/old.domain.com/public_html;
    location / {
        # First attempt to serve request as file, then
        # as directory, then fall back to index.html

        # Uncomment to enable naxsi on this location
        # include /etc/nginx/naxsi.rules

rewrite /photos/2013+example+race/ http://photos.domain.com/13-example-race permanent;

try_files $uri @404_redirect;
}

location @404_redirect {
    return 301 http://photos.domain.com;
}
}

1 个答案:

答案 0 :(得分:1)

因为它是正则表达式,+有意义(重复1次或更多次),所以你应该试图逃避+

rewrite /photos/2013\+example\+race/ http://photos.domain.com/13-example-race permanent;