开发者

Redirecting 201109 to 2011/09 in nginx

I'm trying to redirect /201109/ to the directory /2011/09/, but I'm not sure how to do it. This is what I have so far in nginx.conf:

rewrite ^/([0-9]{4})([0-9]{2})/(.*) http://www.domain.com/$2/$3/$4 permanent;

That results in an error:

nginx: [emerg] directive "rewrite" is not terminated by ";" in /usr/local/nginx/conf/nginx.conf:20
nginx: configuration file /usr/local/nginx/conf/nginx.con开发者_JAVA技巧f test failed

Any idea what to do? Thanks in advance!


It is the braces ("{" & "}") causing it to fail. As braces have specific meanings in Nginx, when you use them in nginx regexes, you need to enclose the regex string in double quotes.

So this should work for you:

rewrite "^/([0-9]{4})([0-9]{2})/(.*)" http://www.domain.com/$1/$2/$3 permanent;
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜