【问题标题】:Redirecting 201109 to 2011/09 in nginx在 nginx 中将 201109 重定向到 2011/09
【发布时间】:2011-09-25 04:26:43
【问题描述】:

我正在尝试将 /201109/ 重定向到目录 /2011/09/,但我不知道该怎么做。这是我到目前为止在 nginx.conf 中的内容:

rewrite ^/([0-9]{4})([0-9]{2})/(.*) @987654321@$2/$3/$4 permanent;

这会导致错误:

nginx: [emerg] directive "rewrite" is not terminated by ";" in /usr/local/nginx/conf/nginx.conf:20
nginx: configuration file /usr/local/nginx/conf/nginx.conf test failed

知道该怎么做吗?提前致谢!

【问题讨论】:

    标签: redirect nginx


    【解决方案1】:

    是大括号(“{”和“}”)导致它失败。由于大括号在 Nginx 中具有特定的含义,因此在 nginx 正则表达式中使用它们时,需要将正则表达式字符串用双引号括起来。

    所以这应该适合你:

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

    【讨论】:

      猜你喜欢
      • 2015-01-21
      • 1970-01-01
      • 2020-09-11
      • 2015-11-12
      • 2011-03-29
      • 2018-01-05
      • 1970-01-01
      • 1970-01-01
      • 2016-01-07
      相关资源
      最近更新 更多